/* * (non-Javadoc) * * @see com.taobao.metamorphosis.client.SessionFactory#close() */ @Override public void shutdown() throws MetaClientException { if (shutdown) { return; } shutdown = true; // if (this.diamondManager != null) { // this.diamondManager.close(); // } recoverManager.shutdown(); // this.localMessageStorageManager.shutdown(); for (final Shutdownable child : children) { child.shutdown(); } try { remotingClient.stop(); } catch (final NotifyRemotingException e) { throw new NetworkException("Stop remoting client failed", e); } if (zkClient != null) { zkClient.close(); } if (!isHutdownHookCalled) { Runtime.getRuntime().removeShutdownHook(shutdownHook); } }
private IRubyObject shutdownInternal(ThreadContext context, int how) { Channel socketChannel; switch (how) { case 0: socketChannel = openFile.getMainStream().getDescriptor().getChannel(); try { if (socketChannel instanceof SocketChannel || socketChannel instanceof DatagramChannel) { asSocket().shutdownInput(); } else if (socketChannel instanceof Shutdownable) { ((Shutdownable) socketChannel).shutdownInput(); } } catch (IOException e) { throw context.getRuntime().newIOError(e.getMessage()); } if (openFile.getPipeStream() != null) { openFile.setMainStream(openFile.getPipeStream()); openFile.setPipeStream(null); } openFile.setMode(openFile.getMode() & ~OpenFile.READABLE); return RubyFixnum.zero(context.getRuntime()); case 1: socketChannel = openFile.getMainStream().getDescriptor().getChannel(); try { if (socketChannel instanceof SocketChannel || socketChannel instanceof DatagramChannel) { asSocket().shutdownOutput(); } else if (socketChannel instanceof Shutdownable) { ((Shutdownable) socketChannel).shutdownOutput(); } } catch (IOException e) { throw context.getRuntime().newIOError(e.getMessage()); } openFile.setPipeStream(null); openFile.setMode(openFile.getMode() & ~OpenFile.WRITABLE); return RubyFixnum.zero(context.getRuntime()); case 2: shutdownInternal(context, 0); shutdownInternal(context, 1); return RubyFixnum.zero(context.getRuntime()); default: throw context.getRuntime().newArgumentError("`how' should be either 0, 1, 2"); } }