[jboss-svn-commits] JBL Code SVN: r6682 - labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Oct 7 17:16:03 EDT 2006
Author: jokum
Date: 2006-10-07 17:16:01 -0400 (Sat, 07 Oct 2006)
New Revision: 6682
Added:
labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractActiveListener.java
labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java
Log:
Implementation HttpListener
Added: labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractActiveListener.java
===================================================================
--- labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractActiveListener.java 2006-10-07 21:15:39 UTC (rev 6681)
+++ labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/AbstractActiveListener.java 2006-10-07 21:16:01 UTC (rev 6682)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners;
+
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.helpers.DomElement;
+
+/**
+ * Base abstract message listener implementation.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public abstract class AbstractActiveListener extends AbstractListener {
+
+ protected AbstractActiveListener(GpListener p_oDad, DomElement p_oParms,
+ ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(p_oDad, p_oParms, actionDefinitionFactory);
+ } // __________________________________
+
+ /**
+ * Implement run method for this Runnable <p/> Will continue to run until
+ * controlling class (ref in m_oDad) indicates no more looping allowed for
+ * all child classes <p/> This condition will not prevent child processes to
+ * finish normally
+ */
+ public void run() {
+ while (m_oDad.continueLooping()) {
+ Object[] processList = receive();
+
+ for (Object message : processList) {
+ ActionProcessingPipeline runner = new ActionProcessingPipeline(
+ message);
+ this.pipelineExecutorPool.submit(runner);
+ }
+ }
+ }
+
+ /**
+ * Receive message from underlying channel implementation.
+ * <p/>
+ * Implementations must perform a blocking receive.
+ * @return An array of Objects received on the channel.
+ */
+ protected abstract Object[] receive();
+
+ /**
+ * Close the listener implemenation. <p/> Allows the listener to perform
+ * relevant close/cleanup tasks.
+ */
+ protected abstract void close();
+
+} // ____________________________________________________________________________
Added: labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java
===================================================================
--- labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java 2006-10-07 21:15:39 UTC (rev 6681)
+++ labs/jbossesb/workspace/jokum/product/core/listeners/src/org/jboss/soa/esb/listeners/HttpListener.java 2006-10-07 21:16:01 UTC (rev 6682)
@@ -0,0 +1,211 @@
+package org.jboss.soa.esb.listeners;
+
+import java.util.concurrent.Future;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.soa.esb.actions.ActionDefinitionFactory;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.helpers.DomElement;
+
+/**
+ * Http listener implementation using the JBoss Remoting channel.
+ *
+ * The listener will listen to messages on the configured listenHttpUrl. If this is not set, the default
+ * http://localhost:5400 will be used.
+ *
+ * Sample listener Configuration:
+ *
+ * <HttpListenerTest listenerClass="org.jboss.soa.esb.listeners.HttpListener" actions="HttpInvocationToFile"/>
+
+ * <pre>
+ * <HttpListener listenerClass="org.jboss.soa.esb.listeners.HttpListener" actions="ObjectToFile" listenHttpUrl="http://localhost:8800"> *
+ * </HttpListener>
+ * </pre>
+ *
+ * <pre>
+ * <HttpListener listenerClass="org.jboss.soa.esb.listeners.HttpListener" actions="ObjectToFile"> *
+ * </HttpListener>
+ * </pre>
+ *
+ * @author <a href="mailto:johan.kumps at telenet.be">Johan Kumps</a>
+ *
+ */
+public class HttpListener extends AbstractListener implements
+ ServerInvocationHandler {
+
+ /* The logger for this class */
+ protected Logger logger = Logger.getLogger(HttpListener.class);
+
+ /* Boolean indicating whether the info logging level is enabled */
+ protected boolean info = this.logger.isInfoEnabled();
+
+ /* The url this listener will listen on */
+ private static final String LISTEN_HTTP_URL = "listenHttpUrl";
+
+ /* The url to listen on */
+ public String listenHttpUrl = null;
+
+ /* The default transport this listener will listen on */
+ private static final String transport = "http";
+
+ /* The default hostname this listener will listen on */
+ private static final String host = "localhost";
+
+ /* The default port this listener will listen on */
+ private static final int port = 5400;
+
+ /**
+ * Constructor initialising this HttpListener
+ *
+ * @param commandListener
+ * @param listenerConfig
+ * @param actionDefinitionFactory
+ * @throws Exception
+ */
+ public HttpListener(GpListener commandListener,
+ DomElement listenerConfig,
+ ActionDefinitionFactory actionDefinitionFactory) throws Exception {
+ super(commandListener, listenerConfig, actionDefinitionFactory);
+ this.checkParams();
+ this.initServer();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.remoting.ServerInvocationHandler#invoke(org.jboss.remoting.InvocationRequest)
+ */
+ @SuppressWarnings("unchecked")
+ public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+ //Retrieving the real payload of this invocationRequest
+ Object payload = invocationRequest.getRequestPayload();
+ if (this.logger.isInfoEnabled()){
+ this.logger.info("HttpInvocationListener is invoked...The given payload is : " + payload);
+ }
+
+ //Eventually delay the action pipeline execution if no thread is available
+ ActionProcessingPipeline pipelineRunner = new ActionProcessingPipeline(payload);
+ Future submit = this.pipelineExecutorPool.submit(pipelineRunner);
+ return submit.get();
+ }
+
+ /**
+ * Adds a callback handler that will listen for callbacks from the server
+ * invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void addListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * Removes the callback handler that was listening for callbacks from the
+ * server invoker handler.
+ *
+ * @param callbackHandler
+ */
+ public void removeListener(InvokerCallbackHandler callbackHandler) {
+ // NO OP as do not handling callback listeners in this example
+ }
+
+ /**
+ * set the mbean server that the handler can reference
+ *
+ * @param server
+ */
+ public void setMBeanServer(MBeanServer server) {
+ // NO OP as do not need reference to MBeanServer for this handler
+ }
+
+ /**
+ * set the invoker that owns this handler
+ *
+ * @param invoker
+ */
+ public void setInvoker(ServerInvoker invoker) {
+ // NO OP as do not need reference back to the server invoker
+ }
+
+ /**
+ * Method getting the url this HttpListener instance is listening on
+ * @return the current listenHttpUrl
+ */
+ public String getListenHttpUrl() {
+ return listenHttpUrl;
+ }
+
+ /**
+ * Method setting the listenHttpUrl property to listen on
+ * @param listenHttpUrl the listenHttpUrl to be used by this HttpListener instance
+ */
+ public void setListenHttpUrl(String listenHttpUrl) {
+ this.listenHttpUrl = listenHttpUrl;
+ }
+
+ @Override
+ protected void processingError(Object initialMessage,
+ ActionProcessor processor, Throwable error) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void processingComplete(Object initialMessage) {
+ }
+
+ /**
+ * Check for mandatory and optional attributes in parameter tree
+ */
+ private void checkParams() throws Exception {
+ // listener url
+ this.listenHttpUrl = GpListener.obtainAtt(this.listenerConfig,
+ LISTEN_HTTP_URL, this.getDefaultListenHttpUrl());
+ }
+
+ /**
+ * Method returning the default listenHttpUrl for this HttpListener instance
+ *
+ * @return the default listen url
+ */
+ private String getDefaultListenHttpUrl() {
+ return HttpListener.transport + "://"
+ + HttpListener.host + ":"
+ + HttpListener.port;
+ }
+
+ /**
+ * Method initialising the remoting deamon
+ *
+ * @throws Exception
+ * when something goes wrong during remoting deamon startup
+ */
+ private void initServer() throws Exception {
+ InvokerLocator locator = new InvokerLocator(this.listenHttpUrl);
+ if (this.logger.isInfoEnabled()) {
+ this.logger.info("Starting remoting server with locator uri of: "
+ + this.listenHttpUrl);
+ }
+ Connector connector = new Connector(locator);
+ connector.create();
+
+ connector.addInvocationHandler("HttpInvocationHandler", this);
+
+ // Starting the server deamon
+ connector.start();
+
+ if (this.logger.isInfoEnabled()) {
+ this.logger.info("HttpListener deamon started successfully!");
+ }
+
+ }
+
+}
More information about the jboss-svn-commits
mailing list