简体   繁体   中英

java.rmi.UnmarshalException in RMI call

Please note.. the question has been cleaned up after waisting lot of EJP's time. (Sincere apologies and deeply appreciate the help extended.)

We have a client-server application. The communication is RMI. We got the following exception in the application just once. The program has been running for over 5 years now but the exception mentioned below has occured just once recently.

The exception is

    java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
    at com.company.server.TopicSessionImpl_Stub.createPublisher(Unknown Source)
    at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.calc(clientClass.java:92)
    at com.company.process.finance.client.transactionservers.clientClass$TailorCalcManager.access$500(clientClass.java:37)
    at com.company.process.finance.client.transactionservers.clientClass.processTransaction(clientClass.java:346)
    at com.company.process.finance.TransactionServer.processTransaction(TransactionServer.java:50)
    at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:120)
    at com.company.products.server.TransactionalProductManager.processTransaction(TransactionalProductManager.java:110)
    at com.company.process.core.Manager$BrokerListener.readITMsg(Manager.java:74)
    at com.company.core.util5.FixedSizeThreadPoolMsgBus$ParallelTask.run(FixedSizeThreadPoolMsgBus.java:37)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.company.server.TestImplConcrete
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    ... 12 more
Caused by: java.io.NotSerializableException: com.company.server.TestImplConcrete
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at com.company.server.TopicSessionImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    ... 1 more

I have gone through some post and they suggest the class TestImplConcrete should made serializable to get away with the exception. I completely aggree that the TestImplConcrete class is NOT serialized. But the question here is, if that is the only thing solving the problem how was the class woring for past 5 years and how is the class still working without any problem?

Note: we just got this issue only once and then, after restarting the process, all works fine. Also please note the question is not related to my code, it is more related to the serialization and RMI.

Code Here:

// The colling class    
Class CallingClass {
    Public void createSubscription (){

        TopicImpl topicPublisher = null;

        try {
            TopicImpl sessionInter = (TopicImpl) Naming.lookup(url);

            if (sessionInter != null) {

                topicPublisher = sessionInter.createMap();   
            }

        } catch (Exception e) {
            Logger.error(e);
        }
    }

}


The colling interface
public interface TopicImpl extends Remote {

    TestImpl createMap() throws RemoteException ;

}

// Concrete class for calling interface
public class TopicImplConcrete implements TopicImpl {

String name = "abc";

// this map is give some value during class initialization
private ConcurrentHashMap<String, TestImplConcrete> concHashMap = new ConcurrentHashMap<String, TestImplConcrete>();

    public TopicPublisher createMap() {
        TestImpl refOfHere = getMethodHere(name);
        return refOfHere;
        }

    public TestImplConcrete getMethodHere(String name) {
        if (name != null) {
            TestImplConcrete ref = concHashMap.get(name);
            if (ref != null)
                return ref;
            synchronized (this) {
                ref = concHashMap.get(name);
                if (ref != null)
                    return ref;
                ref = new TestImplConcrete(name);
                concHashMap.put(name, ref);
                try {
                    if (!ref.isExported()) {
                        UnicastRemoteObject.exportObject(ref);
                        ref.setExported(true);
                    }
                } catch (RemoteException e) {
                    log.error("Remote Exception", e);
                }
            }
            return ref;
        }
        return null;
    }
}

// The interface being sent over..
public interface TestImpl extends Remote {
    public TestImpl getMethod1()  throws RemoteException;
    public void method2()  throws RemoteException;
}

// concrete class for the interface being sent over.
public class TestImplConcrete implements TestImpl {
 private boolean isExportedBoolean;

 public boolean isExported() {
        return isExportedBoolean;
    }

    public void setExported(boolean isExportedBoolean) {
        this.isExportedBoolean = isExportedBoolean;
    }

    public TestImpl getMethod1() {
    // do something
    }

    public void method2() {
    // do something
    }
}

Please Note: the code has been edited to give only the relevent info. Please let me know if more info is required. The same code pasted above has worked fine for several years now. But this one time it showed NotSerializableException .

testImpl不需要可序列化,但如果不是,则它确实需要在通过 RMI 传递或返回时导出。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM