public ThreadPool(int corePoolSize, int maxPoolSize) { this.corePoolSize = corePoolSize; this.maxPoolSize = maxPoolSize; setExecutor(createDefaultExecutor("Axis2 Task", Thread.NORM_PRIORITY, true)); }
/** * Returns the thread factory. * * @return Returns configuration specific thread pool */ public ThreadFactory getThreadPool() { if (threadPool == null) { threadPool = new ThreadPool(); } return threadPool; }
protected ThreadPoolExecutor createDefaultExecutor(final String name, final int priority, final boolean daemon) { ThreadPoolExecutor rc; if (maxPoolSize == Integer.MAX_VALUE) { rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10, TimeUnit.SECONDS, new SynchronousQueue(), new DefaultThreadFactory(name, daemon, priority)); } else { rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10, TimeUnit.SECONDS, new LinkedBlockingQueue(), new DefaultThreadFactory(name, daemon, priority)); } // FIXME: This API is only in JDK 1.6 - Use reflection? // rc.allowCoreThreadTimeOut(true); return rc; }
private void sendMessage(MessageContext messageContext, boolean isResume) { MessageWorker messageWorker = new MessageWorker(messageContext, isResume); // for annonymous sequence messages we have to use the same thread if (isAnonymous){ messageWorker.run(); } else { messageContext.getConfigurationContext().getThreadPool().execute(messageWorker); } }
/** * Start a pool of Workers. For each connection in connectionFactories, * assign a packer listener. This packet listener will trigger when a * message arrives. */ public void start() throws AxisFault { // create thread pool of workers ExecutorService workerPool = new ThreadPoolExecutor( 1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue(), new org.apache.axis2.util.threadpool.DefaultThreadFactory( new ThreadGroup("XMPP Worker thread group"), "XMPPWorker")); Iterator iter = connectionFactories.values().iterator(); while (iter.hasNext()) { XMPPConnectionFactory connectionFactory = (XMPPConnectionFactory) iter.next(); XMPPPacketListener xmppPacketListener = new XMPPPacketListener(connectionFactory,this.configurationContext,workerPool); connectionFactory.listen(xmppPacketListener); } } }
/** * This is to create a separate thread to process business logic invocation. We create a AsyncMessageReceiverWorker * which internally calls the message receiver specified for the operation. * * We send the ACK through the incoming transport and reply through the address specified in replyTo address. * @param messageCtx msgContext the current MessageContext */ private void processAsAsync(MessageContext messageCtx) { AsyncMessageReceiverWorker worker = new AsyncMessageReceiverWorker( messageCtx); if (messageCtx.isDoingMTOM() || messageCtx.isDoingSwA()) { // If we are doing MTOM or SWA then we need to build with attachment, because we are going to close the incoming connection messageCtx.getEnvelope().buildWithAttachments(); } else { // We need to build the envelop since we are going to close the input stream messageCtx.getEnvelope().build(); } messageCtx.getConfigurationContext().getThreadPool().execute( worker); }
public ThreadPool(int corePoolSize, int maxPoolSize) { this.corePoolSize = corePoolSize; this.maxPoolSize = maxPoolSize; setExecutor(createDefaultExecutor("Axis2 Task", Thread.NORM_PRIORITY, true)); }
/** * Returns the thread factory. * * @return Returns configuration specific thread pool */ public ThreadFactory getThreadPool() { if (threadPool == null) { threadPool = new ThreadPool(); } return threadPool; }
/** * Start a pool of Workers. For each connection in connectionFactories, * assign a packer listener. This packet listener will trigger when a * message arrives. */ public void start() throws AxisFault { // create thread pool of workers ExecutorService workerPool = new ThreadPoolExecutor( 1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue(), new org.apache.axis2.util.threadpool.DefaultThreadFactory( new ThreadGroup("XMPP Worker thread group"), "XMPPWorker")); Iterator iter = connectionFactories.values().iterator(); while (iter.hasNext()) { XMPPConnectionFactory connectionFactory = (XMPPConnectionFactory) iter.next(); XMPPPacketListener xmppPacketListener = new XMPPPacketListener(connectionFactory,this.configurationContext,workerPool); connectionFactory.listen(xmppPacketListener); } } }
protected ThreadPoolExecutor createDefaultExecutor(final String name, final int priority, final boolean daemon) { ThreadPoolExecutor rc; if (maxPoolSize == Integer.MAX_VALUE) { rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10, TimeUnit.SECONDS, new SynchronousQueue(), new DefaultThreadFactory(name, daemon, priority)); } else { rc = new ThreadPoolExecutor(corePoolSize, maxPoolSize, 10, TimeUnit.SECONDS, new LinkedBlockingQueue(), new DefaultThreadFactory(name, daemon, priority)); } // FIXME: This API is only in JDK 1.6 - Use reflection? // rc.allowCoreThreadTimeOut(true); return rc; }
public void startServer() throws IOException { if (serverSocket == null) { if (endpoint.getHost() != null) { InetAddress address = InetAddress.getByName(endpoint.getHost()); serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog(), address); } else { serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog()); } } started = true; endpoint.getListener().getConfigurationContext().getThreadPool().execute(this); log.info("TCP server started on port : " + endpoint.getPort()); }
public ThreadPool() { setExecutor(createDefaultExecutor("Axis2 Task", Thread.NORM_PRIORITY, true)); }
/** * This is to create a separate thread to process business logic invocation. We create a AsyncMessageReceiverWorker * which internally calls the message receiver specified for the operation. * * We send the ACK through the incoming transport and reply through the address specified in replyTo address. * @param messageCtx msgContext the current MessageContext */ private void processAsAsync(MessageContext messageCtx) { AsyncMessageReceiverWorker worker = new AsyncMessageReceiverWorker( messageCtx); if (messageCtx.isDoingMTOM() || messageCtx.isDoingSwA()) { // If we are doing MTOM or SWA then we need to build with attachment, because we are going to close the incoming connection messageCtx.getEnvelope().buildWithAttachments(); } else { // We need to build the envelop since we are going to close the input stream messageCtx.getEnvelope().build(); } messageCtx.getConfigurationContext().getThreadPool().execute( worker); }
public ThreadPool() { setExecutor(createDefaultExecutor("Axis2 Task", Thread.NORM_PRIORITY, true)); }
private void sendMessage(MessageContext messageContext, MessageContext responseMessageContext, boolean isResume, boolean isInvokeAsAnonClient, boolean isUseSameThread) { MessageWorker messageWorker = new MessageWorker(messageContext, responseMessageContext, isResume, isInvokeAsAnonClient); if (isInvokeAsAnonClient){ messageWorker.setRmsSequence(this); } if (isUseSameThread) { messageWorker.run(); } else { // we need to invoke this as annonymous client messageContext.getConfigurationContext().getThreadPool().execute(messageWorker); } }
public void startServer() throws IOException { if (serverSocket == null) { if (endpoint.getHost() != null) { InetAddress address = InetAddress.getByName(endpoint.getHost()); serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog(), address); } else { serverSocket = new ServerSocket(endpoint.getPort(), endpoint.getBacklog()); } } started = true; endpoint.getListener().getConfigurationContext().getThreadPool().execute(this); log.info("TCP server started on port : " + endpoint.getPort()); }
public synchronized void soapFaultOccured() throws AxisFault { terminateRMSSequence(); if (this.errorCallback != null) { ErrorCallbackWorker errorCallbackWorker = new ErrorCallbackWorker(this.errorCallback, new SoapProcessingFaultException("Problem with processing the soap message")); this.axis2Info.getConfigurationContext().getThreadPool().execute(errorCallbackWorker); } }
public synchronized void invalidCreateSequenceResponseReceived() throws AxisFault { terminateRMSSequence(); if (this.errorCallback != null){ ErrorCallbackWorker errorCallbackWorker = new ErrorCallbackWorker(this.errorCallback, new RMSequenceCreationException("Invalid Sequence Response Received")); this.axis2Info.getConfigurationContext().getThreadPool().execute(errorCallbackWorker); } }
public synchronized void rmsSequenceExpired() throws AxisFault { terminateRMSSequence(); if (this.errorCallback != null){ ErrorCallbackWorker errorCallbackWorker = new ErrorCallbackWorker(this.errorCallback, new RMSExpiresException("RMS Sequence has expires before properly terminating the sequence")); this.axis2Info.getConfigurationContext().getThreadPool().execute(errorCallbackWorker); } }