3

I was trying to serialize and deserialize a gov.nist.javax.sip.stack.SIPDialog object into Cassandra. But the equals comparison on the deserialized object fails when I compare it with the original SIPDialog object I serialized. SO looks like I am missing something here in serialisation. I am using a ByteArraySerializer to read/write the bytes into Cassandra.

//Saving Dialog

MutationBatch mutationBatch = createMutator();
byte[] dialogBytes = SIPDialogEntity.serializeDialog(dialog);

mutationBatch.withRow(SIPDIALOGS, dialogId)
.putColumn("dialog".getBytes(),dialogBytes,null);
mutationBatch.execute();

public static byte[] serializeDialog(SIPDialog dialog) throws IOException {

    ByteArrayOutputStream bStream = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bStream);       
    oos.writeObject(dialog);
    oos.close();
    byte[] bytes = bStream.toByteArray();
    bStream.close();

    return bytes;
}   

//Reading Dialog

Column<byte[]> result;
result = getKeySpace().prepareQuery(SIPDIALOGS).getKey(dialogId).getColumn("dialog").execute().getResult();
        sipDialog = SIPDialogEntity.deserializeDialog(result.getByteArrayValue());

public static SIPDialog deserializeDialog(byte[] byteArrayDialog) throws IOException, ClassNotFoundException {      
    System.out.println("DEBUG Reading Dialog Bytes:" + byteArrayDialog );       
    ByteArrayInputStream bStream = new ByteArrayInputStream(byteArrayDialog);
    ObjectInputStream ois = new ObjectInputStream(bStream);     
    SIPDialog dialog = (SIPDialog) ois.readObject();
    ois.close();
    bStream.close();
    return dialog;
}   
jeera
  • 591
  • 1
  • 7
  • 15

2 Answers2

2

The SIPDialog class doesn't override the equals method which is why it fails the comparison. Please open an issue in jain sip at http://java.net/jira/browse/JSIP

jeand
  • 2,325
  • 14
  • 12
  • Thx. Wish I could also hear from anyone that have successfully saved and restored the dialogs for robustness in crash scenarios. – jeera Oct 19 '12 at 10:32
  • 1
    We actually do in Mobicents SIP Servlets (http://code.google.com/p/sipservlets/) and Mobicents JAIN SLEE http://code.google.com/p/jain-slee/ and the code has been in production for quite some time. We store it in JBoss Cache though. You can see the extension we created to the JAIN SIP Stack here http://code.google.com/p/jain-sip/ in the HA project : Provides extensions done by TeleStax, Inc. to provide high availability and fault tolerance through replication of various states of the stack. It supports Call Established Failover or Early Dialog Failover. – jeand Oct 26 '12 at 10:59
  • jeand, Thats very helpful. So cassandra can be used in place of JBoss cache I suppose? – jeera Nov 19 '12 at 08:00
  • Yes, a new back end can be created for Cassandra and plugged easily into the current JAIN SIP HA without too much trouble. Would you like to contribute such a back end ? – jeand Nov 19 '12 at 09:18
0

hmmmm, If SipDialog is your class, you could just skip all the work and use PlayOrm for cassandra ;). Then you don't need to deal with serializing/deserializing.

If it is not your class, I think I will get them to add a way to add 3rd party beans to be converted to an entity much like Guice does in a binding file so it can bind to an entity that can be saved by PlayOrm. IF you open a ticket on PlayOrm with a request, we could get the feature in probably in as little as 1 week.

Dean Hiller
  • 19,235
  • 25
  • 129
  • 212