Instead of using that service variable you can get the same thing with
this statement:

 

        MessageService msgService =
(MessageService)getDestination().getService();

 

Jeff

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of strykker75
Sent: Thursday, May 01, 2008 5:44 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] error with old flex data service code

 

I have some code that was created a couple years ago, when flex data
services was young. I am trying to use it now, but can't seem to get
the java files working. I am having trouble in particular with the
ChatAdapter file:

package chat;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import flex.messaging.FlexSession;
import flex.messaging.FlexContext;
import flex.messaging.FlexSessionListener;
import flex.messaging.messages.AsyncMessage;
import flex.messaging.messages.Message;
import flex.messaging.services.MessageService;
import flex.messaging.services.ServiceAdapter;
import flex.messaging.util.UUIDUtils;

public class ChatAdapter extends ServiceAdapter implements
FlexSessionListener {

private Map sessions;

private String clientId = UUIDUtils.createUUID(false);

public ChatAdapter() {
sessions = Collections.synchronizedMap(new HashMap());
FlexSession.addSessionCreatedListener(this);
}

public Object invoke(Message message) {

// Get Session Id
FlexSession flexSession = FlexContext.getFlexSession();
String sessionId = flexSession.getId();

// Check if Session Id is already registered in HashMap 
if (!sessions.containsKey(sessionId)) {
// Get User Id from message body 
Map body = (Map) message.getBody();
String userId = (String) body.get("userId");
// Register session / userId mapping
System.out.println("*** Registering " + userId
+ " " + sessionId);
sessions.put(sessionId, userId);
}

MessageService msgService = (MessageService) service;
msgService.pushMessageToClients(message, true);
return null;

}

public void sessionCreated(FlexSession session) {
session.addSessionDestroyedListener(this);
}

public void sessionDestroyed(FlexSession session) {
// Get User Id associated with Session Id
String userId = (String) sessions.get(session.getId());
System.out.println("*** Removing " + userId + " " +
session.getId());
// Notify interested parties
pushStatus(userId, "disconnected");
// Remove Session Id / User Id mapping
sessions.remove(session.getId());
}

private void pushStatus(String userId, String status) {
MessageService msgService = (MessageService) service;
AsyncMessage msg = new AsyncMessage();
msg.setDestination("chat");
msg.setHeader("DSSubtopic", "status." + userId);
Map body = new HashMap();
body.put("userId", userId);
body.put("status", status);
msg.setBody(body);
msg.setClientId(clientId);
msg.setMessageId(UUIDUtils.createUUID(false));
msg.setTimestamp(System.currentTimeMillis());
msgService.pushMessageToClients(msg, false);
}

}

The lines that read: 
MessageService msgService = (MessageService) service;
throw compile time errors. I believe that the flex-messaging.jar that
comes with LiveCycle Data Services ES may be different than the
version that shipped with Flex data Services, but that is only
speculation, since I can't seem to find a copy of the older file to
look at. I'm not sure how to correct this file to work with the
current release. Any help would be much appreciated.

 

Reply via email to