Hello all...On my current project, we are building a simple messaging
component into our flex application. Messages can be sent by users as
well as "system" generated. It is the system generated messages that
we want to automatically push to recipients.
We can't seem to get auto-refresh "push" working correctly. Any input
would be greatly appreciated...I've read several messages in this
group, but have yet to solve the issue...
Here is what we have:
Client is using Cairngorm Enterprise and a delegate grabs a reference
to the DataService from the EnterpriseServiceLocator. Upon execution
of the following function, it retrieves the current user's messages:
public function getMessages(messages:ArrayCollection,
userId:int) : void
{
dataService.fill(messages, userId);
}
Server has a corresponding fill method in it's assembler:
@Override
public Collection<Message> fill(List fillParameters) {
List<Message> messages = messageDAO.getMessages(
(Integer)fillParameters.get(0));
return messages;
}
At this point, all is well...the current user's messages get populated
in a data grid (without any intervention on the client) with the data
provider being the "messages" which are passed to the getMessages()
function.
Now the problems start...while a user is logged in, "system" messages
are at times created, and we'd like to automatically push these to the
appropriate users. It _almost_ works, but I've had to make some "hacks"...
To push messages, we are using the DataServiceTransaction as follows:
public void sendMessage(Message message, MsgAddress... recipients) {
messageDAO.sendMessage(message, recipients);
// Push this message to the clients...
try {
DataServiceTransaction tran =
DataServiceTransaction.begin(false);
tran.createItem("messageService", message);
// Only refreshFill for "recipients" of this messages...
for ( MsgAddress recipient : message.getRecipients() ) {
List<Integer> fillParameters = new ArrayList<Integer>(1);
fillParameters.add(recipient.getClarioUser().getId());
tran.refreshFill("messageService", fillParameters);
}
tran.commit();
} catch ( Exception x ) {
String msg = "Problem pushing message: " + x.getMessage();
LOG.error(msg, x);
throw new ClarioException(msg);
}
}
We have also overridden the refreshFill method in our assembler as
follows:
@Override
public int refreshFill(
List fillParams,
Object item,
boolean isCreate
) {
// By default, excute the fill...
int fill = EXECUTE_FILL;
Message message = (Message) item;
if ( fillParams.size() == 1) {
// Only refresh the "recipient" of this message
Integer userId = (Integer) fillParams.get(0);
for ( MsgAddress recipient : message.getRecipients() ) {
if ( recipient.getClarioUser().getId().equals(userId) ) {
fill = APPEND_TO_FILL;
break;
}
}
fill = DO_NOT_EXECUTE_FILL;
}
return fill;
}
The first system message that is generated is pushed to the client
without issue...subsequent messages get pushed (We can see them while
debugging the client), but the messages are never added to the
datagrid. Also, we've noticed some strange behavior where null values
are added to the datagrid???
To get around this, we've implemented the following hacks:
- Add an event listener for MessageEvent to the DataService. When
valid "Message" objects are received, append them to the datagrid's
provider.
- Add a filter function to the data provider ArrayCollection to
prevent the null values from being added.
Any ideas??? We started w/ the simplest case by just implementing fill
in the assembler, which didn't work correctly...and ended up here...
Thanks,
-Chris