Java 序列化/反序列化SIPDIalog

Java 序列化/反序列化SIPDIalog,java,cassandra,sip,jain-sip,astyanax,Java,Cassandra,Sip,Jain Sip,Astyanax,我试图将gov.nist.javax.sip.stack.SIPDialog对象序列化并反序列化为Cassandra。但是,当我将反序列化对象与我序列化的原始SIPDialog对象进行比较时,反序列化对象上的equals比较失败。看来我在连载中遗漏了一些东西。我正在使用ByteArraySerializer将字节读/写到Cassandra中 //保存对话框 MutationBatch mutationBatch = createMutator(); byte[] dialogBytes = SI

我试图将gov.nist.javax.sip.stack.SIPDialog对象序列化并反序列化为Cassandra。但是,当我将反序列化对象与我序列化的原始SIPDialog对象进行比较时,反序列化对象上的equals比较失败。看来我在连载中遗漏了一些东西。我正在使用ByteArraySerializer将字节读/写到Cassandra中

//保存对话框

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;
}   
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;
}   
//阅读对话

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;
}   
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;
}   
列结果;
结果=getKeySpace().prepareQuery(SIPDIALOGS).getKey(dialogId).getColumn(“对话框”).execute().getResult();
sipDialog=SIPDialogEntity.deserializeDialog(result.getByteArrayValue());
公共静态SIPDialog反序列化对话框(字节[]byteArrayDialog)引发IOException,ClassNotFoundException{
System.out.println(“调试读取对话框字节:“+byteArrayDialog”);
ByteArrayInputStream bStream=新的ByteArrayInputStream(byteArrayDialog);
ObjectInputStream ois=新ObjectInputStream(bStream);
SIPDialog=(SIPDialog)ois.readObject();
ois.close();
b stream.close();
返回对话框;
}   

hmmmm,如果SipDialog是您的类,您可以跳过所有工作,使用PlayOrm for cassandra;)。这样就不需要处理序列化/反序列化


如果不是您的类,我想我会让他们添加一种方法,添加第三方bean以转换为实体,就像Guice在绑定文件中所做的那样,这样它就可以绑定到可以由PlayOrm保存的实体。如果您通过请求在PlayOrm上打开一个票证,我们可能会在一周内获得该功能。

SIPDialog类不会覆盖equals方法,这就是它无法进行比较的原因。请在jain sip中打开问题,网址为

Thx。希望我也能听到任何人成功地保存和恢复了对话框,以便在崩溃场景中保持健壮性。实际上,我们在Mobicents SIP Servlets()和Mobicents JAIN SLEE中都做到了这一点,并且代码已经投入生产相当一段时间了。但我们将其存储在JBoss缓存中。您可以在HA项目中看到我们为JAIN SIP堆栈创建的扩展:提供TeleStax,Inc.完成的扩展,通过复制堆栈的各种状态来提供高可用性和容错性。它支持调用已建立的故障转移或早期对话框故障转移。jeand,这非常有用。所以我想cassandra可以代替JBoss缓存吗?是的,可以为cassandra创建一个新的后端,并且可以轻松地插入当前的JAIN SIP HA,而不会有太多麻烦。你愿意贡献这样一个后端吗?