workerthread.java

来自「java开源的企业总线.xmlBlaster」· Java 代码 · 共 74 行

JAVA
74
字号
/*------------------------------------------------------------------------------Name:      WorkerThread.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.client.protocol.socket;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.protocol.socket.SocketUrl;import org.xmlBlaster.util.xbformat.MsgInfo;import java.io.IOException;/** * Takes a received messages and invokes the desired action.  * <p /> * Usually this is an update() or probably a ping() */public class WorkerThread extends Thread{   private final String ME;      private static Logger log = Logger.getLogger(WorkerThread.class.getName());   /** Contains the received message */   private final MsgInfo parser;   /** The manager class, my creator and my destiny */   private final SocketCallbackImpl cbHandler;   /**    * Creates the thread.     */   public WorkerThread(Global glob, SocketCallbackImpl cbHandler, MsgInfo receiver) {      super("XmlBlaster."+cbHandler.getType()+".cbWorkerThread");      this.cbHandler = cbHandler;      this.ME = "WorkerThread-" + cbHandler.getSocketConnection().getLoginName();      this.parser = receiver;   }   /**    * Starts the thread which calls update() into client code.     */   public void run() {      try {         if (log.isLoggable(Level.FINE)) log.fine("Starting worker thread, invoking client code with received message");         cbHandler.receiveReply(this.parser, SocketUrl.SOCKET_TCP);  // Parse the message and invoke callback to client code         if (log.isLoggable(Level.FINE)) log.fine("Worker thread done");      }      catch (XmlBlasterException e) {         log.severe(e.toString());      }      catch (Throwable e) {         if (!(e instanceof IOException)) e.printStackTrace();         if (e instanceof java.net.SocketException) { // : Socket closed            if (log.isLoggable(Level.FINE)) log.fine("Shutting down because of: " + e.toString());         }         else {            log.severe("Shutting down because of: " + e.toString());         }         try {            cbHandler.getSocketConnection().shutdown();         }         catch (XmlBlasterException ex) {            log.severe("run() could not shutdown correctly. " + ex.getMessage());         }      }   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?