In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what is the key role of socket in Thrift. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
TNonblockingServerSocket:
Public TNonblockingServerSocket (NonblockingAbstractServerSocketArgs args) throws TTransportException {clientTimeout_ = args.clientTimeout; try {serverSocketChannel = ServerSocketChannel.open (); serverSocketChannel.configureBlocking (false); / / Make server socket serverSocket_ = serverSocketChannel.socket (); / / Prevent 2MSL delay problem on server restarts serverSocket_.setReuseAddress (true); / / whether to reuse address / / Bind to listening port serverSocket_.bind (args.bindAddr, args.backlog) / / number of backlog acceptable connections} catch (IOException ioe) {serverSocket_ = null; throw new TTransportException ("Could not create ServerSocket on address" + args.bindAddr.toString () + ".", ioe);}} public void listen () throws TTransportException {/ / Make sure not to block on accept if (serverSocket_! = null) {try {serverSocket_.setSoTimeout (0) } catch (SocketException sx) {LOGGER.error ("Socket exception while setting socket timeout", sx);}
TNonblockingServer:
Private SelectAcceptThread selectAcceptThread_; / / internal new event, listening thread / / parent class has corresponding startup operation-- serve (); public TNonblockingServer (AbstractNonblockingServerArgs args) {super (args);}
SelectAcceptThread
Public void run () {try {if (eventHandler_! = null) {eventHandler_.preServe ();} while (! stopped_) {select (); processInterestChanges ();} for (SelectionKey selectionKey: selector.keys ()) {cleanupSelectionKey (selectionKey) } catch (Throwable t) {LOGGER.error ("run () exiting due to uncaught error", t);} finally {try {selector.close ();} catch (IOException e) {LOGGER.error ("Got an IOException while closing selector!", e);} stopped_ = true }} private void select () {try {/ / wait for io events. Selector.select (); / / process the io events we received Iterator selectedKeys = selector.selectedKeys (). Iterator (); while (! stopped_ & & selectedKeys.hasNext ()) {SelectionKey key = selectedKeys.next (); selectedKeys.remove (); / / skip if not valid if (! key.isValid ()) {cleanupSelectionKey (key); continue } / / if the key is marked Accept, then it has to be the server / / transport. If (key.isAcceptable ()) {handleAccept ();} else if (key.isReadable ()) {/ / deal with reads handleRead (key);} else if (key.isWritable ()) {/ / deal with writes handleWrite (key);} else {LOGGER.warn ("Unexpected state in select!" + key.interestOps ()) } catch (IOException e) {LOGGER.warn ("Got an IOException while selecting!", e);}} / * * Do the work required to read from a readable client. If the frame is * fully read, then invoke the method call. * / protected void handleRead (SelectionKey key) {FrameBuffer buffer = (FrameBuffer) key.attachment (); if (! buffer.read ()) {cleanupSelectionKey (key); return;} / / if the buffer's frame read is complete, invoke the method. If (buffer.isFrameFullyRead ()) {if (! requestInvoke (buffer)) {/ / callback, through the thread pool, call the invoke () method in FrameBuffer to read cleanupSelectionKey (key);} / / create a new thread for callback protected boolean requestInvoke (FrameBuffer frameBuffer) {try {Runnable invocation = getRunnable (frameBuffer); invoker.execute (invocation); return true } catch (RejectedExecutionException rx) {LOGGER.warn ("ExecutorService rejected execution!", rx); return false;}} protected Runnable getRunnable (FrameBuffer frameBuffer) {return new Invocation (frameBuffer);} / / callback method class Invocation implements Runnable {private final FrameBuffer frameBuffer; public Invocation (final FrameBuffer frameBuffer) {this.frameBuffer = frameBuffer;} public void run () {frameBuffer.invoke ();}
FrameBuffer:
Public void invoke () {frameTrans_.reset (buffer_.array ()); response_.reset (); try {if (eventHandler_! = null) {eventHandler_.processContext (context_, inTrans_, outTrans_);} processorFactory_.getProcessor (inTrans_) .process (inProt_, outProt_); responseReady (); return } catch (TException te) {LOGGER.warn ("Exception while invoking!", te);} catch (Throwable t) {LOGGER.error ("Unexpected throwable while invoking!", t);} / / This will only be reached when there is a throwable. State_ = FrameBufferState.AWAITING_CLOSE; requestSelectInterestChange ();} what is the key role of socket in Thrift? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.