4

サーバー コンポーネントをシャットダウンするときに問題が発生しており、助けを求めていました。

私のサーバーコードは次のようになります。サーバーをシャットダウンする方法があります

サーバ

    private final String address = "127.0.0.1";
    private Registry registry;
    private int port = 6789;

    public RmiServer() throws RemoteException {
        try {
            registry = LocateRegistry.createRegistry(port);
            registry.rebind("rmiServer", this);
        } catch (RemoteException e) {
            logger.error("Unable to start the server. Exiting the application.", e);
            System.exit(-1);
        }
    }


    public void shutDownServer() throws RemoteException {
        int succesful = 0;
        try {
            registry.unbind("rmiServer");
            UnicastRemoteObject.unexportObject(this, true);
            Thread.sleep(1000);
        } catch (NotBoundException e) {
            logger.error("Error shutting down the server - could not unbind the registry", e);
            succesful = -1;
        } catch (InterruptedException e) {
            logger.info("Unable to sleep when shutting down the server", e);
            succesful = -1;
        }
        catch (AccessException e) {
            logger.info("Access Exception", e);
            succesful = -1;
        }
        catch (UnmarshalException e) {
            System.out.println(e.detail.getMessage());
            logger.info("UnMarshall Exception", e);
            succesful = -1;
        }
        catch (RemoteException e) {
            System.out.println(e.detail.getMessage());
            logger.info("Remote Exception", e);
            succesful = -1;
        }

        logger.info("server shut down gracefully");     
        System.exit(succesful);
}

私のクライアントは正常に接続し、問題はないので、シャットダウンするために新しいアプリケーションを作成し、クライアントコードをコピーして接続し、サーバーで close メソッドを呼び出します

シャットダウン

公開クラスのシャットダウン {

private String serverAddress = "127.0.0.1";
private String serverPort = "6789";
private ReceiveMessageInterface rmiServer;
private Registry registry;

public Shutdown(){
    try {
        registry = LocateRegistry.getRegistry(serverAddress, (new Integer(serverPort)).intValue());
        rmiServer = (ReceiveMessageInterface) (registry.lookup("rmiServer"));
        logger.info("Client started correctly");
        rmiServer.shutDownServer();
        System.exit(0);
    }
    catch (UnmarshalException e ){
        logger.error("Unmarshall exception. Exiting application", e);
        System.exit(-1);
    }
    catch (RemoteException e) {
        logger.error("Remote object exception occured when connecting to server. Exiting application", e);
        System.exit(-1);
    } catch (NotBoundException e) {
        logger.error("Not Bound Exception occured when connecting to server. Exiting application", e);
        System.exit(-1);
    }
}

何を試しても、次の例外が発生し続けます。

ERROR com.rmi.client.RMIClient - Unmarshall exception. Exiting application
java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is: 
    java.net.SocketException: Connection reset
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
    at $Proxy0.shutDownServer(Unknown Source)
    at com.rmi.shutdown.Shutdown.<init>(Shutdown.java:31)
    at com.rmi.shutdown.Shutdown.main(Shutdown.java:52)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at java.io.DataInputStream.readByte(Unknown Source)
    ... 7 more

これは、クライアントが適切に切断されておらず、「切断」されていることが原因である可能性があると思いますが、サーバー側を切断する方法が他にわかりませんか?

誰かアドバイスしてください。

ありがとう

4

2 に答える 2

1

システムは、あなたが指示したことを正確に実行しています。自分自身をアンエクスポートするように指示し、'force' パラメータを true に設定すると、進行中の通話が中止されたため、自身をアンエクスポートして進行中の通話を中止しました。それを無視するか、シャットダウンしたクライアントへのクリーンな応答を主張する場合は、サーバーにアンエクスポート操作用の新しいスレッドを開始させ、シャットダウン コールがクライアントに返されるように少し遅延します。

于 2013-04-25T22:36:57.123 に答える