You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Doug Fischer <dg...@dfischer.com> on 2006/05/10 22:33:48 UTC

Basic TCP component

Does anyone know if a basic TCP component is available?  What I would like
to be able to do is simply extend from a TCP component, set the host and
port in the servicemix.xml file, and have access to the input and output
streams in my implementation class.  I would then want to be able to read
from the input stream and create a NormalizedMessage to put on the bus and
also be able to get a message from the bus and write it to the output
stream.

Is there anything like this out there?

Thanks,
Doug

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
Ok, so I was tasked to give servicemix support for tcp/udp/etc... support. 
I'm thinking of reusing apache mina as used in camel since it is pretty
straightforward.  Thoughts on creating a single component that supports all
those endpoint types?

-jeff


James.Strachan wrote:
> 
> BTW you could reuse the MINA component from Camel inside ServiceMix?
> 
> http://activemq.apache.org/camel/mina.html
> 
> On 10/05/2006, Doug Fischer <dg...@dfischer.com> wrote:
>> Does anyone know if a basic TCP component is available?  What I would
>> like
>> to be able to do is simply extend from a TCP component, set the host and
>> port in the servicemix.xml file, and have access to the input and output
>> streams in my implementation class.  I would then want to be able to read
>> from the input stream and create a NormalizedMessage to put on the bus
>> and
>> also be able to get a message from the bus and write it to the output
>> stream.
>>
>> Is there anything like this out there?
>>
>> Thanks,
>> Doug
>>
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source SOA
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Basic-TCP-component-tf1595103s12049.html#a13104358
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by James Strachan <ja...@gmail.com>.
BTW you could reuse the MINA component from Camel inside ServiceMix?

http://activemq.apache.org/camel/mina.html

On 10/05/2006, Doug Fischer <dg...@dfischer.com> wrote:
> Does anyone know if a basic TCP component is available?  What I would like
> to be able to do is simply extend from a TCP component, set the host and
> port in the servicemix.xml file, and have access to the input and output
> streams in my implementation class.  I would then want to be able to read
> from the input stream and create a NormalizedMessage to put on the bus and
> also be able to get a message from the bus and write it to the output
> stream.
>
> Is there anything like this out there?
>
> Thanks,
> Doug
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com

Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
Components are responsible for creating their own threads.
Lifecycles methods should not be blocking.

Once you fill ok with your code, please raise a JIRA and attach a zip
with all the classes / test resources inside.

Cheers,
Guillaume Nodet

On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> Hopefully this time the attachment will go through.  I am not exactly sure
> why it didn't before.  It is a zip file.
>
> I guess I was thinking that when the component is deployed into the
> lwcontainer that it would be running in its own thread anyway.  Apparently I
> was incorrect in my assumption.
>
> I am still trying to get a grasp on the whole ServiceMix thing so please
> excuse my ignorance.
>
> Thanks,
> Doug
>
>
> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>
> > I think the attachment have been lost.
> >
> > Btw, for a tcp consumer that creates a server socket, it has to wait
> > for incoming connections, so how can you not start a thread ? The
> > jabber api uses a listener, so it is really different.
> >
> > Cheers,
> > Guillaume Nodet
> >
> > On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> >> I have attached my TcpComponentSupport class to this email.  If you could be
> >> so kind to take a look at it and let me know if it looks ok.  You mentioned
> >> that the start method should start a Thread and then kill that Thread in the
> >> stop method.  I am not actually doing this right now however I of course
> >> could implement it that way if necessary.  I attempted to use the
> >> JabberComponentSupport class as a template.
> >>
> >> Please let me know your thoughts.
> >>
> >> Thanks,
> >> Doug
> >>
> >>
> >> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>
> >>> Not sure to understand the problem.
> >>> Usually a lightweight consumer BC will begin to receive messages when
> >>> the component is started.  It means that all the necessary
> >>> configuration parameters have been set.
> >>> The tcp component needs to start a thread inside the start method (and
> >>> kill it inside the stop method).
> >>>
> >>> The second problem is related to components / service units lifecycle.
> >>> When a lightweight component is deployed to the lwcontainer, he has a
> >>> specific lifecycle: when the service unit is started, the component is
> >>> started and when the service unit is stopped, the component is
> >>> shutdown.
> >>>
> >>> But the problem should only occur when someone sends something on the socket
> >>> ...
> >>>
> >>> Cheers,
> >>> Guillaume Nodet
> >>>
> >>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>> Guillaume,
> >>>>
> >>>> Yes you are right, I did ask before (somehow I got sidetracked an forgot
> >>>> all
> >>>> about it).  Anyway, thank you for the reply though.
> >>>>
> >>>> I have been able to implement a TcpComponentSupport class, at least I think
> >>>> so anyway.  The problem that I am having now is that as soon as I deploy
> >>>> the
> >>>> component it starts collecting data and pushing it to the bus.  I have run
> >>>> into a couple of problems because of this.  The first problem is while
> >>>> testing, I would like to extend from TestSupport and use the
> >>>> assertMessagesReceived(), however when it loads the ApplicationContext, the
> >>>> concrete TcpComponentSupport class simply begins communicating over the
> >>>> socket and the test method with the assertMessagesReceived() call is never
> >>>> executed.  The test will just run forever.
> >>>>
> >>>> The second question that I have is along the same lines.  I would like to
> >>>> create a service unit, with simply this component in it and deploy it to
> >>>> ServiceMix and then use something like eip to route the messages where I
> >>>> want them.  The same kind of problem occurs in this scenario, as soon as
> >>>> the
> >>>> service unit is deployed, it will start collecting data from the stream and
> >>>> trying to push it to the bus, the problem is that there is no destination
> >>>> assigned to the the component yet so it tries to send it to "service: null
> >>>> and interface null".
> >>>>
> >>>> Do you have any ideas?
> >>>>
> >>>> Thank you,
> >>>> Doug
> >>>>
> >>>>
> >>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>>>
> >>>>> It seems there's none -- if I recall, you have already asked this question
> >>>>> ;)
> >>>>> However, it should not be very difficult to implement.
> >>>>> You have to inherit the
> >>>>> org.apache.servicemix.components.util.ComponentSupport and implements
> >>>>> MessageExchangeListener.  Then, just create your socket and read it :)
> >>>>> You may need another lw component for sending over tcp, also.
> >>>>>
> >>>>> Cheers,
> >>>>> Guillaume Nodet
> >>>>>
> >>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>>>> Does anyone know if a basic TCP component is available?  What I would
> >>>>>> like
> >>>>>> to be able to do is simply extend from a TCP component, set the host and
> >>>>>> port in the servicemix.xml file, and have access to the input and output
> >>>>>> streams in my implementation class.  I would then want to be able to read
> >>>>>> from the input stream and create a NormalizedMessage to put on the bus
> >>>>>> and
> >>>>>> also be able to get a message from the bus and write it to the output
> >>>>>> stream.
> >>>>>>
> >>>>>> Is there anything like this out there?
> >>>>>>
> >>>>>> Thanks,
> >>>>>> Doug
> >>>>>>
> >>>>>>
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >>
> >>
> >
>
>
>

Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
Problems with transport level protocols is that they are, well,
transport level.  So the application need to define an application
level protocol on top of these (such as http which sits on top of
tcp).  Mina has good support for such thing iirc, so it's really worth
taking a look at it.

On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>
> Hmmm...  So maybe it makes more sense to re-use this in ServiceMix.  It would
> be nice to have something that is bundled with servicemix that allows for
> tcp/udp/etc protocols.
>
>
> Andrea Zoppello-2 wrote:
> >
> > In spagic we've one component to handle low level tcp protocol:
> >
> > Take a look at it: http://forge.objectweb.org/projects/spagic
> >
> > Andrea Zoppello
> >
> > jpuro ha scritto:
> >> Has a standard jbi BC component been created for this yet?  I think not,
> >> but
> >> was curious.
> >>
> >> -jeff
> >>
> >>
> >> dfischer wrote:
> >>
> >>> Forget it, here is the code.  So sorry for so many emails.
> >>>
> >>>
> >>> package org.apache.servicemix.components.tcp;
> >>>
> >>> import org.apache.log4j.Logger;
> >>>
> >>> import java.io.IOException;
> >>> import java.io.InputStream;
> >>> import java.io.OutputStream;
> >>> import java.net.ConnectException;
> >>> import java.net.InetSocketAddress;
> >>> import java.net.Socket;
> >>> import java.net.SocketException;
> >>> import java.nio.channels.SocketChannel;
> >>>
> >>> import javax.jbi.JBIException;
> >>> import javax.jbi.messaging.InOnly;
> >>> import javax.jbi.messaging.MessageExchange;
> >>> import javax.jbi.messaging.MessagingException;
> >>> import javax.jbi.messaging.NormalizedMessage;
> >>> import javax.xml.transform.TransformerException;
> >>>
> >>> import org.apache.servicemix.MessageExchangeListener;
> >>> import org.apache.servicemix.components.util.ComponentSupport;
> >>> import org.springframework.beans.factory.InitializingBean;
> >>>
> >>> public abstract class TcpComponentSupport extends ComponentSupport
> >>> implements
> >>>         MessageExchangeListener, InitializingBean {
> >>>     /**
> >>>      * Logger for this class
> >>>      */
> >>>     private static final Logger log = Logger
> >>>             .getLogger(TcpComponentSupport.class);
> >>>
> >>>     private String host;
> >>>     private int port = -1;
> >>>     private boolean useNIO = false;
> >>>     private int retryInterval = 10000;
> >>>     protected SocketChannel socketChannel = null;
> >>>     private Socket socket = null;
> >>>     protected InputStream in = null;
> >>>     protected OutputStream out = null;
> >>>     protected boolean running = false;
> >>>     private TcpMarshaler marshaler = new TcpMarshaler();
> >>>
> >>>     protected abstract void processConnection() throws JBIException,
> >>> IOException;
> >>>     protected abstract void processIncomingMessage(String tcpMessage);
> >>>
> >>>     public void setHost(String host) {
> >>>         this.host = host;
> >>>     } // en dof setHost(String)(
> >>>
> >>>     public void setPort(int port) {
> >>>         this.port = port;
> >>>     } // en dof setPort(int)
> >>>
> >>>     public void setUseNIO(boolean useNIO) {
> >>>         this.useNIO = useNIO;
> >>>     } // end of setUserNIO(boolean)
> >>>
> >>>     public void setRetryInterval(int retryInterval) {
> >>>         this.retryInterval = retryInterval;
> >>>     } // end of setRetryInterval(int)
> >>>
> >>>     protected boolean getUseNIO() {
> >>>         return this.useNIO;
> >>>     } // end of getUseNIO()
> >>>
> >>>     protected String getHost() {
> >>>         return this.host;
> >>>     } // en dof getHost()
> >>>
> >>>     protected int getPort() {
> >>>         return this.port;
> >>>     } // en dof getPort()
> >>>
> >>>     public void onMessageExchange(MessageExchange exchange)
> >>>             throws MessagingException {
> >>>         String tcpMessage = null;
> >>>         try {
> >>>             tcpMessage =
> >>> this.marshaler.fromNMS(exchange.getMessage("in"));
> >>>             this.processIncomingMessage(tcpMessage);
> >>>             this.done(exchange);
> >>>         } catch (TransformerException e) {
> >>>             throw new MessagingException(e);
> >>>         } // end of try /catch
> >>>     } // end of onMessageExchange(MessageExchange)
> >>>
> >>>     public void afterPropertiesSet() throws Exception {
> >>>         if (host == null) {
> >>>             throw new IllegalArgumentException("You must specify the
> >>> host
> >>> property.");
> >>>         } // end of if
> >>>
> >>>         if (this.port < 0) {
> >>>             throw new IllegalArgumentException("You must specify the
> >>> port
> >>> property.");
> >>>         } // end of if
> >>>     } // end of afterPropertiesSet()
> >>>
> >>>     public void start() throws JBIException {
> >>>         if (this.useNIO) {
> >>>             // configure the NIO SocketChannel
> >>>             this.startNIO();
> >>>         } else {
> >>>             // this is the default
> >>>             // we will simply open a basic socket and create the Input
> >>> and
> >>> Ooutput Streams
> >>>             this.startNonNIO();
> >>>         } // end of if / else
> >>>     } // end of start()
> >>>
> >>>     public void stop() throws JBIException {
> >>>         if (useNIO) {
> >>>             this.stopNIO();
> >>>         } else {
> >>>             this.stopNonNIO();
> >>>         } // ne do if / else
> >>>     } // end of stop()
> >>>
> >>>     protected void sendToBus(String message) {
> >>>         log.debug("Inside sendToBus(), sending message: " + message);
> >>>         try {
> >>>             InOnly exchange =
> >>> this.getExchangeFactory().createInOnlyExchange();
> >>>             NormalizedMessage normalizedMessage =
> >>> exchange.createMessage();
> >>>             exchange.setInMessage(normalizedMessage);
> >>>             this.marshaler.toNMS(normalizedMessage, message);
> >>>             this.getDeliveryChannel().sendSync(exchange);
> >>>             //done(exchange);
> >>>         } catch (MessagingException me) {
> >>>             throw new TcpConnectionException(me, message);
> >>>         } // end of try / catch
> >>>     } // end of sendToBus(String)
> >>>
> >>>     /**
> >>>      * This is an empty implementation of the init().
> >>>      * This method exists so that the concrete class can override it
> >>>      * if there is something that needs to be done to initialize the
> >>> communication
> >>>      * with the server.
> >>>      *
> >>>      * This method is called after the connection has been made and
> >>> after
> >>> the
> >>>      * Input and Output Streams have been assigned.
> >>>      *
> >>>      * This method is called right before the processConnection().
> >>>      */
> >>>     protected void init() {
> >>>         // nothing is done here
> >>>         // if something needs to be done here in the concrete class
> >>>         // this method is called after the connection is made and the
> >>> Input
> >>> and Output Streams
> >>>         // have been set but before the processConnection()
> >>>     } // end of init()
> >>>
> >>>     /**
> >>>      * This is an empty implementation of the cleanup().
> >>>      *
> >>>      * This method exists so the the concrete class can override it
> >>>      * if there is something that needs to be done to cleanup resources
> >>> before the
> >>>      * connection is shutdown.
> >>>      *
> >>>      * This method is called while the connection is still active and
> >>> the
> >>> Input
> >>>      * and Output Streams are still available.
> >>>      */
> >>>     protected void cleanup() {
> >>>         // nothing is done here
> >>>         // if something needs to be done here in the concrete class
> >>>     } // end of init()
> >>>
> >>>     private void startNIO() throws JBIException {
> >>>         if (log.isInfoEnabled()) {
> >>>             log.info("Using NIO to connect to " + this.host + ":" +
> >>> this.port);
> >>>         } // en dof if
> >>>
> >>>         if (!this.running) {
> >>>             this.connectNIO();
> >>>             try {
> >>>                 this.init();
> >>>                 this.processConnection();
> >>>             } catch (SocketException e) {
> >>>                 this.running = false;
> >>>                 this.startNIO();
> >>>             } catch (IOException ioe) {
> >>>                 throw new JBIException(ioe);
> >>>             } // end of try / catch
> >>>         } // end of if
> >>>     } // end of startNIO()
> >>>
> >>>     private void connectNIO() throws JBIException {
> >>>         try {
> >>>             this.socketChannel = SocketChannel.open();
> >>>             this.socketChannel.configureBlocking(false);
> >>>
> >>>             this.socketChannel.connect(new InetSocketAddress(this.host,
> >>> this.port));
> >>>             int count = 0;
> >>>             while (!this.socketChannel.finishConnect()) {
> >>>                 log.debug("Finishing connection: " + (count++) + "
> >>> times");
> >>>             } // end of while loop
> >>>
> >>>             this.running = true;
> >>>         } catch (ConnectException ce) {
> >>>             log.warn(this.host + ":" + this.port + " unavailable,
> >>> waiting
> >>> "
> >>> + this.retryInterval + " milliseconds before trying again.");
> >>>             this.running = false;
> >>>             try {
> >>>                 Thread.sleep(this.retryInterval);
> >>>             } catch (InterruptedException e) {}
> >>>             this.connectNIO();
> >>>         } catch (Exception e) {
> >>>             log.error("Exception while trying to make a tcp connection
> >>> to
> >>> "
> >>> + this.host + ":" + this.port);
> >>>             log.error(e);
> >>>             this.running = false;
> >>>             throw new JBIException("Failed to connect to " + this.host +
> >>> ":"
> >>> + this.port, e);
> >>>         } // end of try / catch
> >>>     } // end of connectNIO()
> >>>
> >>>     private void startNonNIO() throws JBIException {
> >>>         if (log.isInfoEnabled()) {
> >>>             log.info("Using basic sockets to connect to " + this.host +
> >>> ":"
> >>> + this.port);
> >>>         } // en dof if
> >>>
> >>>         if (!this.running) {
> >>>             this.connectNonNIO();
> >>>             try {
> >>>                 this.init();
> >>>                 this.processConnection();
> >>>             } catch (SocketException e) {
> >>>                 this.running = false;
> >>>                 this.startNonNIO();
> >>>             } catch (IOException ioe) {
> >>>                 throw new JBIException(ioe);
> >>>             } // end of try / catch
> >>>         } // end of if
> >>>     } // end of startNonNIO()
> >>>
> >>>     private void connectNonNIO() throws JBIException {
> >>>         try {
> >>>             this.socket = new Socket(this.host, this.port);
> >>>
> >>>             this.in = this.socket.getInputStream();
> >>>             this.out = this.socket.getOutputStream();
> >>>
> >>>             this.running = true;
> >>>         } catch (ConnectException ce) {
> >>>             log.warn(this.host + ":" + this.port + " unavailable,
> >>> waiting
> >>> "
> >>> + this.retryInterval + " milliseconds before trying again.");
> >>>             this.running = false;
> >>>             try {
> >>>                 Thread.sleep(this.retryInterval);
> >>>             } catch (InterruptedException e) {}
> >>>             this.connectNonNIO();
> >>>         } catch (Exception e) {
> >>>             log.error("Exception while trying to make a tcp connection
> >>> to
> >>> "
> >>> + this.host + ":" + this.port);
> >>>             log.error(e);
> >>>             this.running = false;
> >>>             throw new JBIException("Failed to connect to " + this.host +
> >>> ":"
> >>> + this.port, e);
> >>>         } // end of try / catch
> >>>     } // end of connectNonNIO()
> >>>
> >>>     private void stopNIO() throws JBIException {
> >>>         log.debug("Inside stopNIO()");
> >>>         if (this.socketChannel != null) {
> >>>             this.cleanup();
> >>>             try {
> >>>                 this.socketChannel.close();
> >>>                 this.socketChannel = null;
> >>>                 this.running = false;
> >>>             } catch (IOException e) {
> >>>                 throw new JBIException("Unable to close connection", e);
> >>>             } // end of try / catch
> >>>         } // end of if
> >>>     } // end of stopNIO()
> >>>
> >>>     private void stopNonNIO() throws JBIException {
> >>>         log.debug("Inside stopNonNIO()");
> >>>         if (this.socket != null) {
> >>>             if (this.socket.isConnected()) {
> >>>                 this.cleanup();
> >>>                 try {
> >>>                     this.socket.close();
> >>>                     this.in = null;
> >>>                     this.out = null;
> >>>                     this.socket = null;
> >>>                     this.running = false;
> >>>                 } catch (IOException e) {
> >>>                     throw new JBIException("Unable to close connection",
> >>> e);
> >>>                 } // end of try / catch
> >>>             } // end of if
> >>>         } // end of if
> >>>     } // end of stopNonNIO()
> >>> } // end of class TcpComponentSupport
> >>>
> >>>
> >>>
> >>> On 5/12/06 11:49 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
> >>>
> >>>
> >>>> Sorry, let me try it again with just the .java file.
> >>>>
> >>>>
> >>>> On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
> >>>>
> >>>>
> >>>>> Hopefully this time the attachment will go through.  I am not exactly
> >>>>> sure
> >>>>> why it didn't before.  It is a zip file.
> >>>>>
> >>>>> I guess I was thinking that when the component is deployed into the
> >>>>> lwcontainer that it would be running in its own thread anyway.
> >>>>> Apparently I
> >>>>> was incorrect in my assumption.
> >>>>>
> >>>>> I am still trying to get a grasp on the whole ServiceMix thing so
> >>>>> please
> >>>>> excuse my ignorance.
> >>>>>
> >>>>> Thanks,
> >>>>> Doug
> >>>>>
> >>>>>
> >>>>> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>>>>
> >>>>>
> >>>>>> I think the attachment have been lost.
> >>>>>>
> >>>>>> Btw, for a tcp consumer that creates a server socket, it has to wait
> >>>>>> for incoming connections, so how can you not start a thread ? The
> >>>>>> jabber api uses a listener, so it is really different.
> >>>>>>
> >>>>>> Cheers,
> >>>>>> Guillaume Nodet
> >>>>>>
> >>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>>>>
> >>>>>>> I have attached my TcpComponentSupport class to this email.  If you
> >>>>>>> could
> >>>>>>> be
> >>>>>>> so kind to take a look at it and let me know if it looks ok.  You
> >>>>>>> mentioned
> >>>>>>> that the start method should start a Thread and then kill that
> >>>>>>> Thread
> >>>>>>> in
> >>>>>>> the
> >>>>>>> stop method.  I am not actually doing this right now however I of
> >>>>>>> course
> >>>>>>> could implement it that way if necessary.  I attempted to use the
> >>>>>>> JabberComponentSupport class as a template.
> >>>>>>>
> >>>>>>> Please let me know your thoughts.
> >>>>>>>
> >>>>>>> Thanks,
> >>>>>>> Doug
> >>>>>>>
> >>>>>>>
> >>>>>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>>>>>>
> >>>>>>>
> >>>>>>>> Not sure to understand the problem.
> >>>>>>>> Usually a lightweight consumer BC will begin to receive messages
> >>>>>>>> when
> >>>>>>>> the component is started.  It means that all the necessary
> >>>>>>>> configuration parameters have been set.
> >>>>>>>> The tcp component needs to start a thread inside the start method
> >>>>>>>> (and
> >>>>>>>> kill it inside the stop method).
> >>>>>>>>
> >>>>>>>> The second problem is related to components / service units
> >>>>>>>> lifecycle.
> >>>>>>>> When a lightweight component is deployed to the lwcontainer, he has
> >>>>>>>> a
> >>>>>>>> specific lifecycle: when the service unit is started, the component
> >>>>>>>> is
> >>>>>>>> started and when the service unit is stopped, the component is
> >>>>>>>> shutdown.
> >>>>>>>>
> >>>>>>>> But the problem should only occur when someone sends something on
> >>>>>>>> the
> >>>>>>>> socket
> >>>>>>>> ...
> >>>>>>>>
> >>>>>>>> Cheers,
> >>>>>>>> Guillaume Nodet
> >>>>>>>>
> >>>>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>>>>>>
> >>>>>>>>> Guillaume,
> >>>>>>>>>
> >>>>>>>>> Yes you are right, I did ask before (somehow I got sidetracked an
> >>>>>>>>> forgot
> >>>>>>>>> all
> >>>>>>>>> about it).  Anyway, thank you for the reply though.
> >>>>>>>>>
> >>>>>>>>> I have been able to implement a TcpComponentSupport class, at
> >>>>>>>>> least
> >>>>>>>>> I
> >>>>>>>>> think
> >>>>>>>>> so anyway.  The problem that I am having now is that as soon as I
> >>>>>>>>> deploy
> >>>>>>>>> the
> >>>>>>>>> component it starts collecting data and pushing it to the bus.  I
> >>>>>>>>> have
> >>>>>>>>> run
> >>>>>>>>> into a couple of problems because of this.  The first problem is
> >>>>>>>>> while
> >>>>>>>>> testing, I would like to extend from TestSupport and use the
> >>>>>>>>> assertMessagesReceived(), however when it loads the
> >>>>>>>>> ApplicationContext,
> >>>>>>>>> the
> >>>>>>>>> concrete TcpComponentSupport class simply begins communicating
> >>>>>>>>> over
> >>>>>>>>> the
> >>>>>>>>> socket and the test method with the assertMessagesReceived() call
> >>>>>>>>> is
> >>>>>>>>> never
> >>>>>>>>> executed.  The test will just run forever.
> >>>>>>>>>
> >>>>>>>>> The second question that I have is along the same lines.  I would
> >>>>>>>>> like to
> >>>>>>>>> create a service unit, with simply this component in it and deploy
> >>>>>>>>> it to
> >>>>>>>>> ServiceMix and then use something like eip to route the messages
> >>>>>>>>> where I
> >>>>>>>>> want them.  The same kind of problem occurs in this scenario, as
> >>>>>>>>> soon as
> >>>>>>>>> the
> >>>>>>>>> service unit is deployed, it will start collecting data from the
> >>>>>>>>> stream
> >>>>>>>>> and
> >>>>>>>>> trying to push it to the bus, the problem is that there is no
> >>>>>>>>> destination
> >>>>>>>>> assigned to the the component yet so it tries to send it to
> >>>>>>>>> "service:
> >>>>>>>>> null
> >>>>>>>>> and interface null".
> >>>>>>>>>
> >>>>>>>>> Do you have any ideas?
> >>>>>>>>>
> >>>>>>>>> Thank you,
> >>>>>>>>> Doug
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>> It seems there's none -- if I recall, you have already asked this
> >>>>>>>>>> question
> >>>>>>>>>> ;)
> >>>>>>>>>> However, it should not be very difficult to implement.
> >>>>>>>>>> You have to inherit the
> >>>>>>>>>> org.apache.servicemix.components.util.ComponentSupport and
> >>>>>>>>>> implements
> >>>>>>>>>> MessageExchangeListener.  Then, just create your socket and read
> >>>>>>>>>> it
> >>>>>>>>>> :)
> >>>>>>>>>> You may need another lw component for sending over tcp, also.
> >>>>>>>>>>
> >>>>>>>>>> Cheers,
> >>>>>>>>>> Guillaume Nodet
> >>>>>>>>>>
> >>>>>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>>>>>>>>
> >>>>>>>>>>> Does anyone know if a basic TCP component is available?  What I
> >>>>>>>>>>> would
> >>>>>>>>>>> like
> >>>>>>>>>>> to be able to do is simply extend from a TCP component, set the
> >>>>>>>>>>> host
> >>>>>>>>>>> and
> >>>>>>>>>>> port in the servicemix.xml file, and have access to the input
> >>>>>>>>>>> and
> >>>>>>>>>>> output
> >>>>>>>>>>> streams in my implementation class.  I would then want to be
> >>>>>>>>>>> able
> >>>>>>>>>>> to
> >>>>>>>>>>> read
> >>>>>>>>>>> from the input stream and create a NormalizedMessage to put on
> >>>>>>>>>>> the
> >>>>>>>>>>> bus
> >>>>>>>>>>> and
> >>>>>>>>>>> also be able to get a message from the bus and write it to the
> >>>>>>>>>>> output
> >>>>>>>>>>> stream.
> >>>>>>>>>>>
> >>>>>>>>>>> Is there anything like this out there?
> >>>>>>>>>>>
> >>>>>>>>>>> Thanks,
> >>>>>>>>>>> Doug
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>
> >>>>>>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Basic-TCP-component-tf1595103s12049.html#a13105397
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
Hmmm.  ok, likelyhood of options 2 and 3???  For my company we can use the
lgpl licensed one, but I'd like this to be out of the box for servicemix, at
least a basic version to begin with...

-jeff

gnodet wrote:
> 
> AFAIK, the one provided by Spagic is LGPL and unless they plan to
> change its license we can't really use it in ServiceMix. So there are
> 3 possibilities:
>    * you don't care about LGPL, so just use it
>    * the component is relicensed under AL
>    * the component is contributed to ServiceMix (which implies it is
> relicensed)
>    * or you start a new one :-(
> 
> On 10/9/07, jpuro <jp...@sterlingtesting.com> wrote:
>>
>> So, what to do about a TCP component?  :)
>>
>> -jeff
>>
>>
>> gnodet wrote:
>> >
>> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> >> Hi Guillaume,
>> >>
>> >> If you take a look at the document "How to cook your spagic" you could
>> >> find all the information, on the patches, enhnacements that we've made
>> >> on servicemix.
>> >>
>> >> Actually spagic is based on smx 3.1.1 codebase.
>> >>
>> >> By the way our approach is to keep the patches that we've done in
>> spagic
>> >> until they're
>> >> taken bu smx codebase.
>> >
>> > Most of the bug you are talking about have been already fixed afaik
>> > (SM-781, SM-924, SM-879).  One is still pending in an unknown state
>> > (SM-888).  You have raised another one recently about the split
>> > aggregator which has been included too (not released yet).  But I
>> > agree some have not been relesed yet :-(
>> >
>> >>
>> >> In future versions of spagic the patches that we've update to JIRA
>> will
>> >> not be there
>> >> anymore, because it will be included directly in smx :-)
>> >
>> > Cool, I think that's the way to go too.  Hopefully we will be able to
>> > have shorter release cycles now.
>> >
>> >>
>> >> By the way have you seen my post about the needing for "Merge
>> >> components" in front
>> >> of a Drools or Content Based router??
>> >>
>> >>
>> >> Andrea Zoppello
>> >>
>> >> Guillaume Nodet ha scritto:
>> >> > Andrea, I've just downloaded the source zip of the components and it
>> >> > seems that there is lots of components coming from ServiceMix: are
>> >> > these differents in some sort ? Bug fixes, enhancements ?  If so
>> what
>> >> > about raising JIRAs and attaching your patches ? I know you have
>> >> > already done so and iirc i have applied them ...
>> >> >
>> >> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> >> >
>> >> >> Hi Bruce,
>> >> >>
>> >> >> You can take a look at:
>> >> >>
>> >> >> http://forge.objectweb.org/projects/spagic
>> >> >>
>> >> >> In the project site you could find the source code.
>> >> >>
>> >> >> By the way some information the spagic TCP component is based on
>> >> apache
>> >> >> mina.
>> >> >>
>> >> >>
>> >> >> Andrea Zoppello
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> Bruce Snyder ha scritto:
>> >> >>
>> >> >>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>> >> >>>
>> >> >>>
>> >> >>>> Yup, that makes sense.  But after looking at spagic it seems that
>> >> they
>> >> >>>> already use mina in a similar fashion and handle a lot of other
>> >> requirements
>> >> >>>> for tcp/ip etc.  Take a look at their source code and let me know
>> >> what you
>> >> >>>> think.  Otherwise I'll just implement my own version on apache
>> mina
>> >> as I
>> >> >>>> have seen camel-mina do.
>> >> >>>>
>> >> >>>>
>> >> >>> Please provide a URL to the source of the code you're looking at.
>> >> >>>
>> >> >>> Bruce
>> >> >>>
>> >> >>>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>> > --
>> > Cheers,
>> > Guillaume Nodet
>> > ------------------------
>> > Blog: http://gnodet.blogspot.com/
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13117891
>> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13136109
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
AFAIK, the one provided by Spagic is LGPL and unless they plan to
change its license we can't really use it in ServiceMix. So there are
3 possibilities:
   * you don't care about LGPL, so just use it
   * the component is relicensed under AL
   * the component is contributed to ServiceMix (which implies it is relicensed)
   * or you start a new one :-(

On 10/9/07, jpuro <jp...@sterlingtesting.com> wrote:
>
> So, what to do about a TCP component?  :)
>
> -jeff
>
>
> gnodet wrote:
> >
> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> >> Hi Guillaume,
> >>
> >> If you take a look at the document "How to cook your spagic" you could
> >> find all the information, on the patches, enhnacements that we've made
> >> on servicemix.
> >>
> >> Actually spagic is based on smx 3.1.1 codebase.
> >>
> >> By the way our approach is to keep the patches that we've done in spagic
> >> until they're
> >> taken bu smx codebase.
> >
> > Most of the bug you are talking about have been already fixed afaik
> > (SM-781, SM-924, SM-879).  One is still pending in an unknown state
> > (SM-888).  You have raised another one recently about the split
> > aggregator which has been included too (not released yet).  But I
> > agree some have not been relesed yet :-(
> >
> >>
> >> In future versions of spagic the patches that we've update to JIRA will
> >> not be there
> >> anymore, because it will be included directly in smx :-)
> >
> > Cool, I think that's the way to go too.  Hopefully we will be able to
> > have shorter release cycles now.
> >
> >>
> >> By the way have you seen my post about the needing for "Merge
> >> components" in front
> >> of a Drools or Content Based router??
> >>
> >>
> >> Andrea Zoppello
> >>
> >> Guillaume Nodet ha scritto:
> >> > Andrea, I've just downloaded the source zip of the components and it
> >> > seems that there is lots of components coming from ServiceMix: are
> >> > these differents in some sort ? Bug fixes, enhancements ?  If so what
> >> > about raising JIRAs and attaching your patches ? I know you have
> >> > already done so and iirc i have applied them ...
> >> >
> >> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> >> >
> >> >> Hi Bruce,
> >> >>
> >> >> You can take a look at:
> >> >>
> >> >> http://forge.objectweb.org/projects/spagic
> >> >>
> >> >> In the project site you could find the source code.
> >> >>
> >> >> By the way some information the spagic TCP component is based on
> >> apache
> >> >> mina.
> >> >>
> >> >>
> >> >> Andrea Zoppello
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> Bruce Snyder ha scritto:
> >> >>
> >> >>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
> >> >>>
> >> >>>
> >> >>>> Yup, that makes sense.  But after looking at spagic it seems that
> >> they
> >> >>>> already use mina in a similar fashion and handle a lot of other
> >> requirements
> >> >>>> for tcp/ip etc.  Take a look at their source code and let me know
> >> what you
> >> >>>> think.  Otherwise I'll just implement my own version on apache mina
> >> as I
> >> >>>> have seen camel-mina do.
> >> >>>>
> >> >>>>
> >> >>> Please provide a URL to the source of the code you're looking at.
> >> >>>
> >> >>> Bruce
> >> >>>
> >> >>>
> >> >>
> >> >
> >> >
> >> >
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> > ------------------------
> > Blog: http://gnodet.blogspot.com/
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13117891
> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
This approach would work fine.  I would also like something to be included
out of the box in ServiceMix.

Thanks,

-jeff

Andrea Zoppello-2 wrote:
> 
> Hi,
> 
> I think servicemix team is looking the code of spagic tcp-ip component.
> 
> By the way i forget to say that if you want you can take the spagic 
> tcp-ip component alone
> and install in a fresh servicemix.
> 
> What's the problem with this approach?
> 
> Andrea
> puro ha scritto:
>> So, what to do about a TCP component?  :)
>>
>> -jeff
>>
>>
>> gnodet wrote:
>>   
>>> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>>>     
>>>> Hi Guillaume,
>>>>
>>>> If you take a look at the document "How to cook your spagic" you could
>>>> find all the information, on the patches, enhnacements that we've made
>>>> on servicemix.
>>>>
>>>> Actually spagic is based on smx 3.1.1 codebase.
>>>>
>>>> By the way our approach is to keep the patches that we've done in
>>>> spagic
>>>> until they're
>>>> taken bu smx codebase.
>>>>       
>>> Most of the bug you are talking about have been already fixed afaik
>>> (SM-781, SM-924, SM-879).  One is still pending in an unknown state
>>> (SM-888).  You have raised another one recently about the split
>>> aggregator which has been included too (not released yet).  But I
>>> agree some have not been relesed yet :-(
>>>
>>>     
>>>> In future versions of spagic the patches that we've update to JIRA will
>>>> not be there
>>>> anymore, because it will be included directly in smx :-)
>>>>       
>>> Cool, I think that's the way to go too.  Hopefully we will be able to
>>> have shorter release cycles now.
>>>
>>>     
>>>> By the way have you seen my post about the needing for "Merge
>>>> components" in front
>>>> of a Drools or Content Based router??
>>>>
>>>>
>>>> Andrea Zoppello
>>>>
>>>> Guillaume Nodet ha scritto:
>>>>       
>>>>> Andrea, I've just downloaded the source zip of the components and it
>>>>> seems that there is lots of components coming from ServiceMix: are
>>>>> these differents in some sort ? Bug fixes, enhancements ?  If so what
>>>>> about raising JIRAs and attaching your patches ? I know you have
>>>>> already done so and iirc i have applied them ...
>>>>>
>>>>> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>>>>>
>>>>>         
>>>>>> Hi Bruce,
>>>>>>
>>>>>> You can take a look at:
>>>>>>
>>>>>> http://forge.objectweb.org/projects/spagic
>>>>>>
>>>>>> In the project site you could find the source code.
>>>>>>
>>>>>> By the way some information the spagic TCP component is based on
>>>>>>           
>>>> apache
>>>>       
>>>>>> mina.
>>>>>>
>>>>>>
>>>>>> Andrea Zoppello
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Bruce Snyder ha scritto:
>>>>>>
>>>>>>           
>>>>>>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>>>>>>>
>>>>>>>
>>>>>>>             
>>>>>>>> Yup, that makes sense.  But after looking at spagic it seems that
>>>>>>>>               
>>>> they
>>>>       
>>>>>>>> already use mina in a similar fashion and handle a lot of other
>>>>>>>>               
>>>> requirements
>>>>       
>>>>>>>> for tcp/ip etc.  Take a look at their source code and let me know
>>>>>>>>               
>>>> what you
>>>>       
>>>>>>>> think.  Otherwise I'll just implement my own version on apache mina
>>>>>>>>               
>>>> as I
>>>>       
>>>>>>>> have seen camel-mina do.
>>>>>>>>
>>>>>>>>
>>>>>>>>               
>>>>>>> Please provide a URL to the source of the code you're looking at.
>>>>>>>
>>>>>>> Bruce
>>>>>>>
>>>>>>>
>>>>>>>             
>>>>>
>>>>>         
>>>>       
>>> -- 
>>> Cheers,
>>> Guillaume Nodet
>>> ------------------------
>>> Blog: http://gnodet.blogspot.com/
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13119876
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Andrea Zoppello <zo...@tiscali.it>.
Hi,

I think servicemix team is looking the code of spagic tcp-ip component.

By the way i forget to say that if you want you can take the spagic 
tcp-ip component alone
and install in a fresh servicemix.

What's the problem with this approach?

Andrea
puro ha scritto:
> So, what to do about a TCP component?  :)
>
> -jeff
>
>
> gnodet wrote:
>   
>> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>>     
>>> Hi Guillaume,
>>>
>>> If you take a look at the document "How to cook your spagic" you could
>>> find all the information, on the patches, enhnacements that we've made
>>> on servicemix.
>>>
>>> Actually spagic is based on smx 3.1.1 codebase.
>>>
>>> By the way our approach is to keep the patches that we've done in spagic
>>> until they're
>>> taken bu smx codebase.
>>>       
>> Most of the bug you are talking about have been already fixed afaik
>> (SM-781, SM-924, SM-879).  One is still pending in an unknown state
>> (SM-888).  You have raised another one recently about the split
>> aggregator which has been included too (not released yet).  But I
>> agree some have not been relesed yet :-(
>>
>>     
>>> In future versions of spagic the patches that we've update to JIRA will
>>> not be there
>>> anymore, because it will be included directly in smx :-)
>>>       
>> Cool, I think that's the way to go too.  Hopefully we will be able to
>> have shorter release cycles now.
>>
>>     
>>> By the way have you seen my post about the needing for "Merge
>>> components" in front
>>> of a Drools or Content Based router??
>>>
>>>
>>> Andrea Zoppello
>>>
>>> Guillaume Nodet ha scritto:
>>>       
>>>> Andrea, I've just downloaded the source zip of the components and it
>>>> seems that there is lots of components coming from ServiceMix: are
>>>> these differents in some sort ? Bug fixes, enhancements ?  If so what
>>>> about raising JIRAs and attaching your patches ? I know you have
>>>> already done so and iirc i have applied them ...
>>>>
>>>> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>>>>
>>>>         
>>>>> Hi Bruce,
>>>>>
>>>>> You can take a look at:
>>>>>
>>>>> http://forge.objectweb.org/projects/spagic
>>>>>
>>>>> In the project site you could find the source code.
>>>>>
>>>>> By the way some information the spagic TCP component is based on
>>>>>           
>>> apache
>>>       
>>>>> mina.
>>>>>
>>>>>
>>>>> Andrea Zoppello
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Bruce Snyder ha scritto:
>>>>>
>>>>>           
>>>>>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>>>>>>
>>>>>>
>>>>>>             
>>>>>>> Yup, that makes sense.  But after looking at spagic it seems that
>>>>>>>               
>>> they
>>>       
>>>>>>> already use mina in a similar fashion and handle a lot of other
>>>>>>>               
>>> requirements
>>>       
>>>>>>> for tcp/ip etc.  Take a look at their source code and let me know
>>>>>>>               
>>> what you
>>>       
>>>>>>> think.  Otherwise I'll just implement my own version on apache mina
>>>>>>>               
>>> as I
>>>       
>>>>>>> have seen camel-mina do.
>>>>>>>
>>>>>>>
>>>>>>>               
>>>>>> Please provide a URL to the source of the code you're looking at.
>>>>>>
>>>>>> Bruce
>>>>>>
>>>>>>
>>>>>>             
>>>>
>>>>         
>>>       
>> -- 
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>>
>>
>>     
>
>   


RE: Basic TCP component

Posted by Hofri Yehuda <Ye...@comverse.com>.
Et voila:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.components.http.HttpClientMarshaler;
import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.w3c.dom.Document;

import javax.jbi.JBIException;
import javax.jbi.messaging.*;
import javax.xml.namespace.QName;

public class HttpClientBC extends ComponentSupport implements
MessageExchangeListener {

  private SourceTransformer _transformer;
    protected HttpClientMarshaler marshaler = new HttpClientMarshaler();
    protected MultiThreadedHttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager();
    protected HttpClient httpClient = new HttpClient(connectionManager);
    protected HostConfiguration hostConfiguration = new
HostConfiguration();
    protected String url;


    public void stop() throws JBIException {
        super.stop();
        connectionManager.shutdown();
    }


    public HttpClientBC() {
       
    }


    public void onMessageExchange(MessageExchange messageExchange)
throws MessagingException {
        InOut inOut = (InOut) messageExchange;
        if (inOut.getStatus() == ExchangeStatus.DONE) {
            return;
        } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
            return;
        }
        try {

            NormalizedMessage inMsg = inOut.getInMessage();
            Document doc = (Document)
_transformer.toDOMNode(inMsg.getContent());

...  Do something with the message ?!

            boolean httpResponse = sendHttpReq();
..... Do something with the response?!

            NormalizedMessage answer = inOut.createMessage();
            answer.setContent(....);

            answer(inOut, answer);
        } catch (Exception e) {
            throw new MessagingException(e);
        }
    }

    private boolean sendHttpReq(String id) {
        PostMethod method = new PostMethod(url);
        try {
            method.addParameter("id", id);
            int response = httpClient.executeMethod(hostConfiguration,
method);

            if (response != HttpStatus.SC_OK && response !=
HttpStatus.SC_ACCEPTED) {
                return false;
            }
        }
        catch (Exception e) {
            return false;
        }
        finally {
            method.releaseConnection();
        }
        return true;
    }


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
} 

-----Original Message-----
From: jpuro [mailto:jpuro@sterlingtesting.com] 
Sent: Tuesday, October 09, 2007 5:33 PM
To: servicemix-dev@geronimo.apache.org
Subject: Re: Basic TCP component


So, what to do about a TCP component?  :)

-jeff


gnodet wrote:
> 
> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> Hi Guillaume,
>>
>> If you take a look at the document "How to cook your spagic" you 
>> could find all the information, on the patches, enhnacements that 
>> we've made on servicemix.
>>
>> Actually spagic is based on smx 3.1.1 codebase.
>>
>> By the way our approach is to keep the patches that we've done in 
>> spagic until they're taken bu smx codebase.
> 
> Most of the bug you are talking about have been already fixed afaik 
> (SM-781, SM-924, SM-879).  One is still pending in an unknown state 
> (SM-888).  You have raised another one recently about the split 
> aggregator which has been included too (not released yet).  But I 
> agree some have not been relesed yet :-(
> 
>>
>> In future versions of spagic the patches that we've update to JIRA 
>> will not be there anymore, because it will be included directly in 
>> smx :-)
> 
> Cool, I think that's the way to go too.  Hopefully we will be able to 
> have shorter release cycles now.
> 
>>
>> By the way have you seen my post about the needing for "Merge 
>> components" in front of a Drools or Content Based router??
>>
>>
>> Andrea Zoppello
>>
>> Guillaume Nodet ha scritto:
>> > Andrea, I've just downloaded the source zip of the components and 
>> > it seems that there is lots of components coming from ServiceMix: 
>> > are these differents in some sort ? Bug fixes, enhancements ?  If 
>> > so what about raising JIRAs and attaching your patches ? I know you

>> > have already done so and iirc i have applied them ...
>> >
>> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> >
>> >> Hi Bruce,
>> >>
>> >> You can take a look at:
>> >>
>> >> http://forge.objectweb.org/projects/spagic
>> >>
>> >> In the project site you could find the source code.
>> >>
>> >> By the way some information the spagic TCP component is based on
>> apache
>> >> mina.
>> >>
>> >>
>> >> Andrea Zoppello
>> >>
>> >>
>> >>
>> >>
>> >> Bruce Snyder ha scritto:
>> >>
>> >>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>> >>>
>> >>>
>> >>>> Yup, that makes sense.  But after looking at spagic it seems 
>> >>>> that
>> they
>> >>>> already use mina in a similar fashion and handle a lot of other
>> requirements
>> >>>> for tcp/ip etc.  Take a look at their source code and let me 
>> >>>> know
>> what you
>> >>>> think.  Otherwise I'll just implement my own version on apache 
>> >>>> mina
>> as I
>> >>>> have seen camel-mina do.
>> >>>>
>> >>>>
>> >>> Please provide a URL to the source of the code you're looking at.
>> >>>
>> >>> Bruce
>> >>>
>> >>>
>> >>
>> >
>> >
>> >
>>
>>
> 
> 
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

--
View this message in context:
http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13
117891
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
So, what to do about a TCP component?  :)

-jeff


gnodet wrote:
> 
> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> Hi Guillaume,
>>
>> If you take a look at the document "How to cook your spagic" you could
>> find all the information, on the patches, enhnacements that we've made
>> on servicemix.
>>
>> Actually spagic is based on smx 3.1.1 codebase.
>>
>> By the way our approach is to keep the patches that we've done in spagic
>> until they're
>> taken bu smx codebase.
> 
> Most of the bug you are talking about have been already fixed afaik
> (SM-781, SM-924, SM-879).  One is still pending in an unknown state
> (SM-888).  You have raised another one recently about the split
> aggregator which has been included too (not released yet).  But I
> agree some have not been relesed yet :-(
> 
>>
>> In future versions of spagic the patches that we've update to JIRA will
>> not be there
>> anymore, because it will be included directly in smx :-)
> 
> Cool, I think that's the way to go too.  Hopefully we will be able to
> have shorter release cycles now.
> 
>>
>> By the way have you seen my post about the needing for "Merge
>> components" in front
>> of a Drools or Content Based router??
>>
>>
>> Andrea Zoppello
>>
>> Guillaume Nodet ha scritto:
>> > Andrea, I've just downloaded the source zip of the components and it
>> > seems that there is lots of components coming from ServiceMix: are
>> > these differents in some sort ? Bug fixes, enhancements ?  If so what
>> > about raising JIRAs and attaching your patches ? I know you have
>> > already done so and iirc i have applied them ...
>> >
>> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>> >
>> >> Hi Bruce,
>> >>
>> >> You can take a look at:
>> >>
>> >> http://forge.objectweb.org/projects/spagic
>> >>
>> >> In the project site you could find the source code.
>> >>
>> >> By the way some information the spagic TCP component is based on
>> apache
>> >> mina.
>> >>
>> >>
>> >> Andrea Zoppello
>> >>
>> >>
>> >>
>> >>
>> >> Bruce Snyder ha scritto:
>> >>
>> >>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>> >>>
>> >>>
>> >>>> Yup, that makes sense.  But after looking at spagic it seems that
>> they
>> >>>> already use mina in a similar fashion and handle a lot of other
>> requirements
>> >>>> for tcp/ip etc.  Take a look at their source code and let me know
>> what you
>> >>>> think.  Otherwise I'll just implement my own version on apache mina
>> as I
>> >>>> have seen camel-mina do.
>> >>>>
>> >>>>
>> >>> Please provide a URL to the source of the code you're looking at.
>> >>>
>> >>> Bruce
>> >>>
>> >>>
>> >>
>> >
>> >
>> >
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13117891
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> Hi Guillaume,
>
> If you take a look at the document "How to cook your spagic" you could
> find all the information, on the patches, enhnacements that we've made
> on servicemix.
>
> Actually spagic is based on smx 3.1.1 codebase.
>
> By the way our approach is to keep the patches that we've done in spagic
> until they're
> taken bu smx codebase.

Most of the bug you are talking about have been already fixed afaik
(SM-781, SM-924, SM-879).  One is still pending in an unknown state
(SM-888).  You have raised another one recently about the split
aggregator which has been included too (not released yet).  But I
agree some have not been relesed yet :-(

>
> In future versions of spagic the patches that we've update to JIRA will
> not be there
> anymore, because it will be included directly in smx :-)

Cool, I think that's the way to go too.  Hopefully we will be able to
have shorter release cycles now.

>
> By the way have you seen my post about the needing for "Merge
> components" in front
> of a Drools or Content Based router??
>
>
> Andrea Zoppello
>
> Guillaume Nodet ha scritto:
> > Andrea, I've just downloaded the source zip of the components and it
> > seems that there is lots of components coming from ServiceMix: are
> > these differents in some sort ? Bug fixes, enhancements ?  If so what
> > about raising JIRAs and attaching your patches ? I know you have
> > already done so and iirc i have applied them ...
> >
> > On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> >
> >> Hi Bruce,
> >>
> >> You can take a look at:
> >>
> >> http://forge.objectweb.org/projects/spagic
> >>
> >> In the project site you could find the source code.
> >>
> >> By the way some information the spagic TCP component is based on apache
> >> mina.
> >>
> >>
> >> Andrea Zoppello
> >>
> >>
> >>
> >>
> >> Bruce Snyder ha scritto:
> >>
> >>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
> >>>
> >>>
> >>>> Yup, that makes sense.  But after looking at spagic it seems that they
> >>>> already use mina in a similar fashion and handle a lot of other requirements
> >>>> for tcp/ip etc.  Take a look at their source code and let me know what you
> >>>> think.  Otherwise I'll just implement my own version on apache mina as I
> >>>> have seen camel-mina do.
> >>>>
> >>>>
> >>> Please provide a URL to the source of the code you're looking at.
> >>>
> >>> Bruce
> >>>
> >>>
> >>
> >
> >
> >
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Basic TCP component

Posted by Andrea Zoppello <zo...@tiscali.it>.
Hi Guillaume,

If you take a look at the document "How to cook your spagic" you could 
find all the information, on the patches, enhnacements that we've made 
on servicemix.

Actually spagic is based on smx 3.1.1 codebase.

By the way our approach is to keep the patches that we've done in spagic 
until they're
taken bu smx codebase.

In future versions of spagic the patches that we've update to JIRA will 
not be there
anymore, because it will be included directly in smx :-)

By the way have you seen my post about the needing for "Merge 
components" in front
of a Drools or Content Based router??


Andrea Zoppello

Guillaume Nodet ha scritto:
> Andrea, I've just downloaded the source zip of the components and it
> seems that there is lots of components coming from ServiceMix: are
> these differents in some sort ? Bug fixes, enhancements ?  If so what
> about raising JIRAs and attaching your patches ? I know you have
> already done so and iirc i have applied them ...
>
> On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
>   
>> Hi Bruce,
>>
>> You can take a look at:
>>
>> http://forge.objectweb.org/projects/spagic
>>
>> In the project site you could find the source code.
>>
>> By the way some information the spagic TCP component is based on apache
>> mina.
>>
>>
>> Andrea Zoppello
>>
>>
>>
>>
>> Bruce Snyder ha scritto:
>>     
>>> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>>>
>>>       
>>>> Yup, that makes sense.  But after looking at spagic it seems that they
>>>> already use mina in a similar fashion and handle a lot of other requirements
>>>> for tcp/ip etc.  Take a look at their source code and let me know what you
>>>> think.  Otherwise I'll just implement my own version on apache mina as I
>>>> have seen camel-mina do.
>>>>
>>>>         
>>> Please provide a URL to the source of the code you're looking at.
>>>
>>> Bruce
>>>
>>>       
>>     
>
>
>   


Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
Andrea, I've just downloaded the source zip of the components and it
seems that there is lots of components coming from ServiceMix: are
these differents in some sort ? Bug fixes, enhancements ?  If so what
about raising JIRAs and attaching your patches ? I know you have
already done so and iirc i have applied them ...

On 10/9/07, Andrea Zoppello <zo...@tiscali.it> wrote:
> Hi Bruce,
>
> You can take a look at:
>
> http://forge.objectweb.org/projects/spagic
>
> In the project site you could find the source code.
>
> By the way some information the spagic TCP component is based on apache
> mina.
>
>
> Andrea Zoppello
>
>
>
>
> Bruce Snyder ha scritto:
> > On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
> >
> >> Yup, that makes sense.  But after looking at spagic it seems that they
> >> already use mina in a similar fashion and handle a lot of other requirements
> >> for tcp/ip etc.  Take a look at their source code and let me know what you
> >> think.  Otherwise I'll just implement my own version on apache mina as I
> >> have seen camel-mina do.
> >>
> >
> > Please provide a URL to the source of the code you're looking at.
> >
> > Bruce
> >
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Basic TCP component

Posted by Andrea Zoppello <zo...@tiscali.it>.
Hi Bruce,

You can take a look at:

http://forge.objectweb.org/projects/spagic

In the project site you could find the source code.

By the way some information the spagic TCP component is based on apache 
mina.


Andrea Zoppello




Bruce Snyder ha scritto:
> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>   
>> Yup, that makes sense.  But after looking at spagic it seems that they
>> already use mina in a similar fashion and handle a lot of other requirements
>> for tcp/ip etc.  Take a look at their source code and let me know what you
>> think.  Otherwise I'll just implement my own version on apache mina as I
>> have seen camel-mina do.
>>     
>
> Please provide a URL to the source of the code you're looking at.
>
> Bruce
>   


Re: Basic TCP component

Posted by Bruce Snyder <br...@gmail.com>.
On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>
> Yup, that makes sense.  But after looking at spagic it seems that they
> already use mina in a similar fashion and handle a lot of other requirements
> for tcp/ip etc.  Take a look at their source code and let me know what you
> think.  Otherwise I'll just implement my own version on apache mina as I
> have seen camel-mina do.

Please provide a URL to the source of the code you're looking at.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Castor - http://castor.org/

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
Yup, that makes sense.  But after looking at spagic it seems that they
already use mina in a similar fashion and handle a lot of other requirements
for tcp/ip etc.  Take a look at their source code and let me know what you
think.  Otherwise I'll just implement my own version on apache mina as I
have seen camel-mina do.

-jeff

bsnyder wrote:
> 
> On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>>
>> Hmmm...  So maybe it makes more sense to re-use this in ServiceMix.  It
>> would
>> be nice to have something that is bundled with servicemix that allows for
>> tcp/udp/etc protocols.
> 
> MINA is an awesome choice for this because it provides a nice
> framework to use for networking instead of the actual low-level
> networking APIs.
> 
> You can implement this style of binding component in ServiceMix by
> starting with the servicemix-binding-component archetype. It creates a
> skeleton Maven project for a binding component and then you go through
> it all and fill in the gaps. You just need to implement a condition to
> determine the request type required (tcp or udp) and then, say, put
> each code block in a corresponding method.
> 
> Here's some on info on doing this with UDP via MINA:
> 
> http://mina.apache.org/udp-tutorial.html
> 
> And here's some info on using TCP sockets with MINA:
> 
> http://mina.apache.org/quick-start-guide.html
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> Apache ActiveMQ - http://activemq.org/
> Apache ServiceMix - http://servicemix.org/
> Apache Geronimo - http://geronimo.apache.org/
> Castor - http://castor.org/
> 
> 

-- 
View this message in context: http://www.nabble.com/Basic-TCP-component-tf1595103s12049.html#a13105703
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Bruce Snyder <br...@gmail.com>.
On 10/8/07, jpuro <jp...@sterlingtesting.com> wrote:
>
> Hmmm...  So maybe it makes more sense to re-use this in ServiceMix.  It would
> be nice to have something that is bundled with servicemix that allows for
> tcp/udp/etc protocols.

MINA is an awesome choice for this because it provides a nice
framework to use for networking instead of the actual low-level
networking APIs.

You can implement this style of binding component in ServiceMix by
starting with the servicemix-binding-component archetype. It creates a
skeleton Maven project for a binding component and then you go through
it all and fill in the gaps. You just need to implement a condition to
determine the request type required (tcp or udp) and then, say, put
each code block in a corresponding method.

Here's some on info on doing this with UDP via MINA:

http://mina.apache.org/udp-tutorial.html

And here's some info on using TCP sockets with MINA:

http://mina.apache.org/quick-start-guide.html

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Apache Geronimo - http://geronimo.apache.org/
Castor - http://castor.org/

Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
Hmmm...  So maybe it makes more sense to re-use this in ServiceMix.  It would
be nice to have something that is bundled with servicemix that allows for
tcp/udp/etc protocols.


Andrea Zoppello-2 wrote:
> 
> In spagic we've one component to handle low level tcp protocol:
> 
> Take a look at it: http://forge.objectweb.org/projects/spagic
> 
> Andrea Zoppello
> 
> jpuro ha scritto:
>> Has a standard jbi BC component been created for this yet?  I think not,
>> but
>> was curious.
>>
>> -jeff
>>
>>
>> dfischer wrote:
>>   
>>> Forget it, here is the code.  So sorry for so many emails.
>>>
>>>
>>> package org.apache.servicemix.components.tcp;
>>>
>>> import org.apache.log4j.Logger;
>>>
>>> import java.io.IOException;
>>> import java.io.InputStream;
>>> import java.io.OutputStream;
>>> import java.net.ConnectException;
>>> import java.net.InetSocketAddress;
>>> import java.net.Socket;
>>> import java.net.SocketException;
>>> import java.nio.channels.SocketChannel;
>>>
>>> import javax.jbi.JBIException;
>>> import javax.jbi.messaging.InOnly;
>>> import javax.jbi.messaging.MessageExchange;
>>> import javax.jbi.messaging.MessagingException;
>>> import javax.jbi.messaging.NormalizedMessage;
>>> import javax.xml.transform.TransformerException;
>>>
>>> import org.apache.servicemix.MessageExchangeListener;
>>> import org.apache.servicemix.components.util.ComponentSupport;
>>> import org.springframework.beans.factory.InitializingBean;
>>>
>>> public abstract class TcpComponentSupport extends ComponentSupport
>>> implements
>>>         MessageExchangeListener, InitializingBean {
>>>     /**
>>>      * Logger for this class
>>>      */
>>>     private static final Logger log = Logger
>>>             .getLogger(TcpComponentSupport.class);
>>>     
>>>     private String host;
>>>     private int port = -1;
>>>     private boolean useNIO = false;
>>>     private int retryInterval = 10000;
>>>     protected SocketChannel socketChannel = null;
>>>     private Socket socket = null;
>>>     protected InputStream in = null;
>>>     protected OutputStream out = null;
>>>     protected boolean running = false;
>>>     private TcpMarshaler marshaler = new TcpMarshaler();
>>>     
>>>     protected abstract void processConnection() throws JBIException,
>>> IOException;
>>>     protected abstract void processIncomingMessage(String tcpMessage);
>>>     
>>>     public void setHost(String host) {
>>>         this.host = host;
>>>     } // en dof setHost(String)(
>>>     
>>>     public void setPort(int port) {
>>>         this.port = port;
>>>     } // en dof setPort(int)
>>>     
>>>     public void setUseNIO(boolean useNIO) {
>>>         this.useNIO = useNIO;
>>>     } // end of setUserNIO(boolean)
>>>     
>>>     public void setRetryInterval(int retryInterval) {
>>>         this.retryInterval = retryInterval;
>>>     } // end of setRetryInterval(int)
>>>     
>>>     protected boolean getUseNIO() {
>>>         return this.useNIO;
>>>     } // end of getUseNIO()
>>>     
>>>     protected String getHost() {
>>>         return this.host;
>>>     } // en dof getHost()
>>>     
>>>     protected int getPort() {
>>>         return this.port;
>>>     } // en dof getPort()
>>>
>>>     public void onMessageExchange(MessageExchange exchange)
>>>             throws MessagingException {
>>>         String tcpMessage = null;
>>>         try {
>>>             tcpMessage =
>>> this.marshaler.fromNMS(exchange.getMessage("in"));
>>>             this.processIncomingMessage(tcpMessage);
>>>             this.done(exchange);
>>>         } catch (TransformerException e) {
>>>             throw new MessagingException(e);
>>>         } // end of try /catch
>>>     } // end of onMessageExchange(MessageExchange)
>>>
>>>     public void afterPropertiesSet() throws Exception {
>>>         if (host == null) {
>>>             throw new IllegalArgumentException("You must specify the
>>> host
>>> property.");
>>>         } // end of if
>>>         
>>>         if (this.port < 0) {
>>>             throw new IllegalArgumentException("You must specify the
>>> port
>>> property.");
>>>         } // end of if
>>>     } // end of afterPropertiesSet()
>>>     
>>>     public void start() throws JBIException {
>>>         if (this.useNIO) {
>>>             // configure the NIO SocketChannel
>>>             this.startNIO();
>>>         } else {
>>>             // this is the default
>>>             // we will simply open a basic socket and create the Input
>>> and
>>> Ooutput Streams
>>>             this.startNonNIO();
>>>         } // end of if / else
>>>     } // end of start()
>>>     
>>>     public void stop() throws JBIException {
>>>         if (useNIO) {
>>>             this.stopNIO();
>>>         } else {
>>>             this.stopNonNIO();
>>>         } // ne do if / else
>>>     } // end of stop()
>>>     
>>>     protected void sendToBus(String message) {
>>>         log.debug("Inside sendToBus(), sending message: " + message);
>>>         try {
>>>             InOnly exchange =
>>> this.getExchangeFactory().createInOnlyExchange();
>>>             NormalizedMessage normalizedMessage =
>>> exchange.createMessage();
>>>             exchange.setInMessage(normalizedMessage);
>>>             this.marshaler.toNMS(normalizedMessage, message);
>>>             this.getDeliveryChannel().sendSync(exchange);
>>>             //done(exchange);
>>>         } catch (MessagingException me) {
>>>             throw new TcpConnectionException(me, message);
>>>         } // end of try / catch
>>>     } // end of sendToBus(String)
>>>     
>>>     /**
>>>      * This is an empty implementation of the init().
>>>      * This method exists so that the concrete class can override it
>>>      * if there is something that needs to be done to initialize the
>>> communication
>>>      * with the server.
>>>      * 
>>>      * This method is called after the connection has been made and
>>> after
>>> the 
>>>      * Input and Output Streams have been assigned.
>>>      * 
>>>      * This method is called right before the processConnection().
>>>      */
>>>     protected void init() {
>>>         // nothing is done here
>>>         // if something needs to be done here in the concrete class
>>>         // this method is called after the connection is made and the
>>> Input
>>> and Output Streams
>>>         // have been set but before the processConnection()
>>>     } // end of init()
>>>     
>>>     /**
>>>      * This is an empty implementation of the cleanup().
>>>      * 
>>>      * This method exists so the the concrete class can override it
>>>      * if there is something that needs to be done to cleanup resources
>>> before the 
>>>      * connection is shutdown.
>>>      * 
>>>      * This method is called while the connection is still active and
>>> the
>>> Input
>>>      * and Output Streams are still available.
>>>      */
>>>     protected void cleanup() {
>>>         // nothing is done here
>>>         // if something needs to be done here in the concrete class
>>>     } // end of init()
>>>     
>>>     private void startNIO() throws JBIException {
>>>         if (log.isInfoEnabled()) {
>>>             log.info("Using NIO to connect to " + this.host + ":" +
>>> this.port);
>>>         } // en dof if
>>>
>>>         if (!this.running) {
>>>             this.connectNIO();
>>>             try {
>>>                 this.init();
>>>                 this.processConnection();
>>>             } catch (SocketException e) {
>>>                 this.running = false;
>>>                 this.startNIO();
>>>             } catch (IOException ioe) {
>>>                 throw new JBIException(ioe);
>>>             } // end of try / catch
>>>         } // end of if
>>>     } // end of startNIO()
>>>     
>>>     private void connectNIO() throws JBIException {
>>>         try {
>>>             this.socketChannel = SocketChannel.open();
>>>             this.socketChannel.configureBlocking(false);
>>>             
>>>             this.socketChannel.connect(new InetSocketAddress(this.host,
>>> this.port));
>>>             int count = 0;
>>>             while (!this.socketChannel.finishConnect()) {
>>>                 log.debug("Finishing connection: " + (count++) + "
>>> times");
>>>             } // end of while loop
>>>             
>>>             this.running = true;
>>>         } catch (ConnectException ce) {
>>>             log.warn(this.host + ":" + this.port + " unavailable,
>>> waiting
>>> "
>>> + this.retryInterval + " milliseconds before trying again.");
>>>             this.running = false;
>>>             try {
>>>                 Thread.sleep(this.retryInterval);
>>>             } catch (InterruptedException e) {}
>>>             this.connectNIO();
>>>         } catch (Exception e) {
>>>             log.error("Exception while trying to make a tcp connection
>>> to
>>> "
>>> + this.host + ":" + this.port);
>>>             log.error(e);
>>>             this.running = false;
>>>             throw new JBIException("Failed to connect to " + this.host +
>>> ":"
>>> + this.port, e);
>>>         } // end of try / catch
>>>     } // end of connectNIO()
>>>     
>>>     private void startNonNIO() throws JBIException {
>>>         if (log.isInfoEnabled()) {
>>>             log.info("Using basic sockets to connect to " + this.host +
>>> ":"
>>> + this.port);
>>>         } // en dof if
>>>         
>>>         if (!this.running) {
>>>             this.connectNonNIO();
>>>             try {
>>>                 this.init();
>>>                 this.processConnection();
>>>             } catch (SocketException e) {
>>>                 this.running = false;
>>>                 this.startNonNIO();
>>>             } catch (IOException ioe) {
>>>                 throw new JBIException(ioe);
>>>             } // end of try / catch
>>>         } // end of if
>>>     } // end of startNonNIO()
>>>     
>>>     private void connectNonNIO() throws JBIException {
>>>         try {
>>>             this.socket = new Socket(this.host, this.port);
>>>             
>>>             this.in = this.socket.getInputStream();
>>>             this.out = this.socket.getOutputStream();
>>>             
>>>             this.running = true;
>>>         } catch (ConnectException ce) {
>>>             log.warn(this.host + ":" + this.port + " unavailable,
>>> waiting
>>> "
>>> + this.retryInterval + " milliseconds before trying again.");
>>>             this.running = false;
>>>             try {
>>>                 Thread.sleep(this.retryInterval);
>>>             } catch (InterruptedException e) {}
>>>             this.connectNonNIO();
>>>         } catch (Exception e) {
>>>             log.error("Exception while trying to make a tcp connection
>>> to
>>> "
>>> + this.host + ":" + this.port);
>>>             log.error(e);
>>>             this.running = false;
>>>             throw new JBIException("Failed to connect to " + this.host +
>>> ":"
>>> + this.port, e);
>>>         } // end of try / catch
>>>     } // end of connectNonNIO()
>>>     
>>>     private void stopNIO() throws JBIException {
>>>         log.debug("Inside stopNIO()");
>>>         if (this.socketChannel != null) {
>>>             this.cleanup();
>>>             try {
>>>                 this.socketChannel.close();
>>>                 this.socketChannel = null;
>>>                 this.running = false;
>>>             } catch (IOException e) {
>>>                 throw new JBIException("Unable to close connection", e);
>>>             } // end of try / catch
>>>         } // end of if
>>>     } // end of stopNIO()
>>>     
>>>     private void stopNonNIO() throws JBIException {
>>>         log.debug("Inside stopNonNIO()");
>>>         if (this.socket != null) {
>>>             if (this.socket.isConnected()) {
>>>                 this.cleanup();
>>>                 try {
>>>                     this.socket.close();
>>>                     this.in = null;
>>>                     this.out = null;
>>>                     this.socket = null;
>>>                     this.running = false;
>>>                 } catch (IOException e) {
>>>                     throw new JBIException("Unable to close connection",
>>> e);
>>>                 } // end of try / catch
>>>             } // end of if
>>>         } // end of if
>>>     } // end of stopNonNIO()
>>> } // end of class TcpComponentSupport
>>>
>>>
>>>
>>> On 5/12/06 11:49 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
>>>
>>>     
>>>> Sorry, let me try it again with just the .java file.
>>>>
>>>>
>>>> On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
>>>>
>>>>       
>>>>> Hopefully this time the attachment will go through.  I am not exactly
>>>>> sure
>>>>> why it didn't before.  It is a zip file.
>>>>>
>>>>> I guess I was thinking that when the component is deployed into the
>>>>> lwcontainer that it would be running in its own thread anyway. 
>>>>> Apparently I
>>>>> was incorrect in my assumption.
>>>>>
>>>>> I am still trying to get a grasp on the whole ServiceMix thing so
>>>>> please
>>>>> excuse my ignorance.
>>>>>
>>>>> Thanks,
>>>>> Doug
>>>>>
>>>>>
>>>>> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>
>>>>>         
>>>>>> I think the attachment have been lost.
>>>>>>
>>>>>> Btw, for a tcp consumer that creates a server socket, it has to wait
>>>>>> for incoming connections, so how can you not start a thread ? The
>>>>>> jabber api uses a listener, so it is really different.
>>>>>>
>>>>>> Cheers,
>>>>>> Guillaume Nodet
>>>>>>
>>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>           
>>>>>>> I have attached my TcpComponentSupport class to this email.  If you
>>>>>>> could
>>>>>>> be
>>>>>>> so kind to take a look at it and let me know if it looks ok.  You
>>>>>>> mentioned
>>>>>>> that the start method should start a Thread and then kill that
>>>>>>> Thread
>>>>>>> in
>>>>>>> the
>>>>>>> stop method.  I am not actually doing this right now however I of
>>>>>>> course
>>>>>>> could implement it that way if necessary.  I attempted to use the
>>>>>>> JabberComponentSupport class as a template.
>>>>>>>
>>>>>>> Please let me know your thoughts.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Doug
>>>>>>>
>>>>>>>
>>>>>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>>>
>>>>>>>             
>>>>>>>> Not sure to understand the problem.
>>>>>>>> Usually a lightweight consumer BC will begin to receive messages
>>>>>>>> when
>>>>>>>> the component is started.  It means that all the necessary
>>>>>>>> configuration parameters have been set.
>>>>>>>> The tcp component needs to start a thread inside the start method
>>>>>>>> (and
>>>>>>>> kill it inside the stop method).
>>>>>>>>
>>>>>>>> The second problem is related to components / service units
>>>>>>>> lifecycle.
>>>>>>>> When a lightweight component is deployed to the lwcontainer, he has
>>>>>>>> a
>>>>>>>> specific lifecycle: when the service unit is started, the component
>>>>>>>> is
>>>>>>>> started and when the service unit is stopped, the component is
>>>>>>>> shutdown.
>>>>>>>>
>>>>>>>> But the problem should only occur when someone sends something on
>>>>>>>> the
>>>>>>>> socket
>>>>>>>> ...
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Guillaume Nodet
>>>>>>>>
>>>>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>>               
>>>>>>>>> Guillaume,
>>>>>>>>>
>>>>>>>>> Yes you are right, I did ask before (somehow I got sidetracked an
>>>>>>>>> forgot
>>>>>>>>> all
>>>>>>>>> about it).  Anyway, thank you for the reply though.
>>>>>>>>>
>>>>>>>>> I have been able to implement a TcpComponentSupport class, at
>>>>>>>>> least
>>>>>>>>> I
>>>>>>>>> think
>>>>>>>>> so anyway.  The problem that I am having now is that as soon as I
>>>>>>>>> deploy
>>>>>>>>> the
>>>>>>>>> component it starts collecting data and pushing it to the bus.  I
>>>>>>>>> have
>>>>>>>>> run
>>>>>>>>> into a couple of problems because of this.  The first problem is
>>>>>>>>> while
>>>>>>>>> testing, I would like to extend from TestSupport and use the
>>>>>>>>> assertMessagesReceived(), however when it loads the
>>>>>>>>> ApplicationContext,
>>>>>>>>> the
>>>>>>>>> concrete TcpComponentSupport class simply begins communicating
>>>>>>>>> over
>>>>>>>>> the
>>>>>>>>> socket and the test method with the assertMessagesReceived() call
>>>>>>>>> is
>>>>>>>>> never
>>>>>>>>> executed.  The test will just run forever.
>>>>>>>>>
>>>>>>>>> The second question that I have is along the same lines.  I would
>>>>>>>>> like to
>>>>>>>>> create a service unit, with simply this component in it and deploy
>>>>>>>>> it to
>>>>>>>>> ServiceMix and then use something like eip to route the messages
>>>>>>>>> where I
>>>>>>>>> want them.  The same kind of problem occurs in this scenario, as
>>>>>>>>> soon as
>>>>>>>>> the
>>>>>>>>> service unit is deployed, it will start collecting data from the
>>>>>>>>> stream
>>>>>>>>> and
>>>>>>>>> trying to push it to the bus, the problem is that there is no
>>>>>>>>> destination
>>>>>>>>> assigned to the the component yet so it tries to send it to
>>>>>>>>> "service:
>>>>>>>>> null
>>>>>>>>> and interface null".
>>>>>>>>>
>>>>>>>>> Do you have any ideas?
>>>>>>>>>
>>>>>>>>> Thank you,
>>>>>>>>> Doug
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>                 
>>>>>>>>>> It seems there's none -- if I recall, you have already asked this
>>>>>>>>>> question
>>>>>>>>>> ;)
>>>>>>>>>> However, it should not be very difficult to implement.
>>>>>>>>>> You have to inherit the
>>>>>>>>>> org.apache.servicemix.components.util.ComponentSupport and
>>>>>>>>>> implements
>>>>>>>>>> MessageExchangeListener.  Then, just create your socket and read
>>>>>>>>>> it
>>>>>>>>>> :)
>>>>>>>>>> You may need another lw component for sending over tcp, also.
>>>>>>>>>>
>>>>>>>>>> Cheers,
>>>>>>>>>> Guillaume Nodet
>>>>>>>>>>
>>>>>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>>>>                   
>>>>>>>>>>> Does anyone know if a basic TCP component is available?  What I
>>>>>>>>>>> would
>>>>>>>>>>> like
>>>>>>>>>>> to be able to do is simply extend from a TCP component, set the
>>>>>>>>>>> host
>>>>>>>>>>> and
>>>>>>>>>>> port in the servicemix.xml file, and have access to the input
>>>>>>>>>>> and
>>>>>>>>>>> output
>>>>>>>>>>> streams in my implementation class.  I would then want to be
>>>>>>>>>>> able
>>>>>>>>>>> to
>>>>>>>>>>> read
>>>>>>>>>>> from the input stream and create a NormalizedMessage to put on
>>>>>>>>>>> the
>>>>>>>>>>> bus
>>>>>>>>>>> and
>>>>>>>>>>> also be able to get a message from the bus and write it to the
>>>>>>>>>>> output
>>>>>>>>>>> stream.
>>>>>>>>>>>
>>>>>>>>>>> Is there anything like this out there?
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Doug
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>                     
>>>>>>>>>
>>>>>>>>>                 
>>>>>>>
>>>>>>>             
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Basic-TCP-component-tf1595103s12049.html#a13105397
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Andrea Zoppello <zo...@tiscali.it>.
In spagic we've one component to handle low level tcp protocol:

Take a look at it: http://forge.objectweb.org/projects/spagic

Andrea Zoppello

jpuro ha scritto:
> Has a standard jbi BC component been created for this yet?  I think not, but
> was curious.
>
> -jeff
>
>
> dfischer wrote:
>   
>> Forget it, here is the code.  So sorry for so many emails.
>>
>>
>> package org.apache.servicemix.components.tcp;
>>
>> import org.apache.log4j.Logger;
>>
>> import java.io.IOException;
>> import java.io.InputStream;
>> import java.io.OutputStream;
>> import java.net.ConnectException;
>> import java.net.InetSocketAddress;
>> import java.net.Socket;
>> import java.net.SocketException;
>> import java.nio.channels.SocketChannel;
>>
>> import javax.jbi.JBIException;
>> import javax.jbi.messaging.InOnly;
>> import javax.jbi.messaging.MessageExchange;
>> import javax.jbi.messaging.MessagingException;
>> import javax.jbi.messaging.NormalizedMessage;
>> import javax.xml.transform.TransformerException;
>>
>> import org.apache.servicemix.MessageExchangeListener;
>> import org.apache.servicemix.components.util.ComponentSupport;
>> import org.springframework.beans.factory.InitializingBean;
>>
>> public abstract class TcpComponentSupport extends ComponentSupport
>> implements
>>         MessageExchangeListener, InitializingBean {
>>     /**
>>      * Logger for this class
>>      */
>>     private static final Logger log = Logger
>>             .getLogger(TcpComponentSupport.class);
>>     
>>     private String host;
>>     private int port = -1;
>>     private boolean useNIO = false;
>>     private int retryInterval = 10000;
>>     protected SocketChannel socketChannel = null;
>>     private Socket socket = null;
>>     protected InputStream in = null;
>>     protected OutputStream out = null;
>>     protected boolean running = false;
>>     private TcpMarshaler marshaler = new TcpMarshaler();
>>     
>>     protected abstract void processConnection() throws JBIException,
>> IOException;
>>     protected abstract void processIncomingMessage(String tcpMessage);
>>     
>>     public void setHost(String host) {
>>         this.host = host;
>>     } // en dof setHost(String)(
>>     
>>     public void setPort(int port) {
>>         this.port = port;
>>     } // en dof setPort(int)
>>     
>>     public void setUseNIO(boolean useNIO) {
>>         this.useNIO = useNIO;
>>     } // end of setUserNIO(boolean)
>>     
>>     public void setRetryInterval(int retryInterval) {
>>         this.retryInterval = retryInterval;
>>     } // end of setRetryInterval(int)
>>     
>>     protected boolean getUseNIO() {
>>         return this.useNIO;
>>     } // end of getUseNIO()
>>     
>>     protected String getHost() {
>>         return this.host;
>>     } // en dof getHost()
>>     
>>     protected int getPort() {
>>         return this.port;
>>     } // en dof getPort()
>>
>>     public void onMessageExchange(MessageExchange exchange)
>>             throws MessagingException {
>>         String tcpMessage = null;
>>         try {
>>             tcpMessage =
>> this.marshaler.fromNMS(exchange.getMessage("in"));
>>             this.processIncomingMessage(tcpMessage);
>>             this.done(exchange);
>>         } catch (TransformerException e) {
>>             throw new MessagingException(e);
>>         } // end of try /catch
>>     } // end of onMessageExchange(MessageExchange)
>>
>>     public void afterPropertiesSet() throws Exception {
>>         if (host == null) {
>>             throw new IllegalArgumentException("You must specify the host
>> property.");
>>         } // end of if
>>         
>>         if (this.port < 0) {
>>             throw new IllegalArgumentException("You must specify the port
>> property.");
>>         } // end of if
>>     } // end of afterPropertiesSet()
>>     
>>     public void start() throws JBIException {
>>         if (this.useNIO) {
>>             // configure the NIO SocketChannel
>>             this.startNIO();
>>         } else {
>>             // this is the default
>>             // we will simply open a basic socket and create the Input and
>> Ooutput Streams
>>             this.startNonNIO();
>>         } // end of if / else
>>     } // end of start()
>>     
>>     public void stop() throws JBIException {
>>         if (useNIO) {
>>             this.stopNIO();
>>         } else {
>>             this.stopNonNIO();
>>         } // ne do if / else
>>     } // end of stop()
>>     
>>     protected void sendToBus(String message) {
>>         log.debug("Inside sendToBus(), sending message: " + message);
>>         try {
>>             InOnly exchange =
>> this.getExchangeFactory().createInOnlyExchange();
>>             NormalizedMessage normalizedMessage =
>> exchange.createMessage();
>>             exchange.setInMessage(normalizedMessage);
>>             this.marshaler.toNMS(normalizedMessage, message);
>>             this.getDeliveryChannel().sendSync(exchange);
>>             //done(exchange);
>>         } catch (MessagingException me) {
>>             throw new TcpConnectionException(me, message);
>>         } // end of try / catch
>>     } // end of sendToBus(String)
>>     
>>     /**
>>      * This is an empty implementation of the init().
>>      * This method exists so that the concrete class can override it
>>      * if there is something that needs to be done to initialize the
>> communication
>>      * with the server.
>>      * 
>>      * This method is called after the connection has been made and after
>> the 
>>      * Input and Output Streams have been assigned.
>>      * 
>>      * This method is called right before the processConnection().
>>      */
>>     protected void init() {
>>         // nothing is done here
>>         // if something needs to be done here in the concrete class
>>         // this method is called after the connection is made and the
>> Input
>> and Output Streams
>>         // have been set but before the processConnection()
>>     } // end of init()
>>     
>>     /**
>>      * This is an empty implementation of the cleanup().
>>      * 
>>      * This method exists so the the concrete class can override it
>>      * if there is something that needs to be done to cleanup resources
>> before the 
>>      * connection is shutdown.
>>      * 
>>      * This method is called while the connection is still active and the
>> Input
>>      * and Output Streams are still available.
>>      */
>>     protected void cleanup() {
>>         // nothing is done here
>>         // if something needs to be done here in the concrete class
>>     } // end of init()
>>     
>>     private void startNIO() throws JBIException {
>>         if (log.isInfoEnabled()) {
>>             log.info("Using NIO to connect to " + this.host + ":" +
>> this.port);
>>         } // en dof if
>>
>>         if (!this.running) {
>>             this.connectNIO();
>>             try {
>>                 this.init();
>>                 this.processConnection();
>>             } catch (SocketException e) {
>>                 this.running = false;
>>                 this.startNIO();
>>             } catch (IOException ioe) {
>>                 throw new JBIException(ioe);
>>             } // end of try / catch
>>         } // end of if
>>     } // end of startNIO()
>>     
>>     private void connectNIO() throws JBIException {
>>         try {
>>             this.socketChannel = SocketChannel.open();
>>             this.socketChannel.configureBlocking(false);
>>             
>>             this.socketChannel.connect(new InetSocketAddress(this.host,
>> this.port));
>>             int count = 0;
>>             while (!this.socketChannel.finishConnect()) {
>>                 log.debug("Finishing connection: " + (count++) + "
>> times");
>>             } // end of while loop
>>             
>>             this.running = true;
>>         } catch (ConnectException ce) {
>>             log.warn(this.host + ":" + this.port + " unavailable, waiting
>> "
>> + this.retryInterval + " milliseconds before trying again.");
>>             this.running = false;
>>             try {
>>                 Thread.sleep(this.retryInterval);
>>             } catch (InterruptedException e) {}
>>             this.connectNIO();
>>         } catch (Exception e) {
>>             log.error("Exception while trying to make a tcp connection to
>> "
>> + this.host + ":" + this.port);
>>             log.error(e);
>>             this.running = false;
>>             throw new JBIException("Failed to connect to " + this.host +
>> ":"
>> + this.port, e);
>>         } // end of try / catch
>>     } // end of connectNIO()
>>     
>>     private void startNonNIO() throws JBIException {
>>         if (log.isInfoEnabled()) {
>>             log.info("Using basic sockets to connect to " + this.host +
>> ":"
>> + this.port);
>>         } // en dof if
>>         
>>         if (!this.running) {
>>             this.connectNonNIO();
>>             try {
>>                 this.init();
>>                 this.processConnection();
>>             } catch (SocketException e) {
>>                 this.running = false;
>>                 this.startNonNIO();
>>             } catch (IOException ioe) {
>>                 throw new JBIException(ioe);
>>             } // end of try / catch
>>         } // end of if
>>     } // end of startNonNIO()
>>     
>>     private void connectNonNIO() throws JBIException {
>>         try {
>>             this.socket = new Socket(this.host, this.port);
>>             
>>             this.in = this.socket.getInputStream();
>>             this.out = this.socket.getOutputStream();
>>             
>>             this.running = true;
>>         } catch (ConnectException ce) {
>>             log.warn(this.host + ":" + this.port + " unavailable, waiting
>> "
>> + this.retryInterval + " milliseconds before trying again.");
>>             this.running = false;
>>             try {
>>                 Thread.sleep(this.retryInterval);
>>             } catch (InterruptedException e) {}
>>             this.connectNonNIO();
>>         } catch (Exception e) {
>>             log.error("Exception while trying to make a tcp connection to
>> "
>> + this.host + ":" + this.port);
>>             log.error(e);
>>             this.running = false;
>>             throw new JBIException("Failed to connect to " + this.host +
>> ":"
>> + this.port, e);
>>         } // end of try / catch
>>     } // end of connectNonNIO()
>>     
>>     private void stopNIO() throws JBIException {
>>         log.debug("Inside stopNIO()");
>>         if (this.socketChannel != null) {
>>             this.cleanup();
>>             try {
>>                 this.socketChannel.close();
>>                 this.socketChannel = null;
>>                 this.running = false;
>>             } catch (IOException e) {
>>                 throw new JBIException("Unable to close connection", e);
>>             } // end of try / catch
>>         } // end of if
>>     } // end of stopNIO()
>>     
>>     private void stopNonNIO() throws JBIException {
>>         log.debug("Inside stopNonNIO()");
>>         if (this.socket != null) {
>>             if (this.socket.isConnected()) {
>>                 this.cleanup();
>>                 try {
>>                     this.socket.close();
>>                     this.in = null;
>>                     this.out = null;
>>                     this.socket = null;
>>                     this.running = false;
>>                 } catch (IOException e) {
>>                     throw new JBIException("Unable to close connection",
>> e);
>>                 } // end of try / catch
>>             } // end of if
>>         } // end of if
>>     } // end of stopNonNIO()
>> } // end of class TcpComponentSupport
>>
>>
>>
>> On 5/12/06 11:49 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
>>
>>     
>>> Sorry, let me try it again with just the .java file.
>>>
>>>
>>> On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
>>>
>>>       
>>>> Hopefully this time the attachment will go through.  I am not exactly
>>>> sure
>>>> why it didn't before.  It is a zip file.
>>>>
>>>> I guess I was thinking that when the component is deployed into the
>>>> lwcontainer that it would be running in its own thread anyway. 
>>>> Apparently I
>>>> was incorrect in my assumption.
>>>>
>>>> I am still trying to get a grasp on the whole ServiceMix thing so please
>>>> excuse my ignorance.
>>>>
>>>> Thanks,
>>>> Doug
>>>>
>>>>
>>>> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>
>>>>         
>>>>> I think the attachment have been lost.
>>>>>
>>>>> Btw, for a tcp consumer that creates a server socket, it has to wait
>>>>> for incoming connections, so how can you not start a thread ? The
>>>>> jabber api uses a listener, so it is really different.
>>>>>
>>>>> Cheers,
>>>>> Guillaume Nodet
>>>>>
>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>           
>>>>>> I have attached my TcpComponentSupport class to this email.  If you
>>>>>> could
>>>>>> be
>>>>>> so kind to take a look at it and let me know if it looks ok.  You
>>>>>> mentioned
>>>>>> that the start method should start a Thread and then kill that Thread
>>>>>> in
>>>>>> the
>>>>>> stop method.  I am not actually doing this right now however I of
>>>>>> course
>>>>>> could implement it that way if necessary.  I attempted to use the
>>>>>> JabberComponentSupport class as a template.
>>>>>>
>>>>>> Please let me know your thoughts.
>>>>>>
>>>>>> Thanks,
>>>>>> Doug
>>>>>>
>>>>>>
>>>>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>>
>>>>>>             
>>>>>>> Not sure to understand the problem.
>>>>>>> Usually a lightweight consumer BC will begin to receive messages when
>>>>>>> the component is started.  It means that all the necessary
>>>>>>> configuration parameters have been set.
>>>>>>> The tcp component needs to start a thread inside the start method
>>>>>>> (and
>>>>>>> kill it inside the stop method).
>>>>>>>
>>>>>>> The second problem is related to components / service units
>>>>>>> lifecycle.
>>>>>>> When a lightweight component is deployed to the lwcontainer, he has a
>>>>>>> specific lifecycle: when the service unit is started, the component
>>>>>>> is
>>>>>>> started and when the service unit is stopped, the component is
>>>>>>> shutdown.
>>>>>>>
>>>>>>> But the problem should only occur when someone sends something on the
>>>>>>> socket
>>>>>>> ...
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Guillaume Nodet
>>>>>>>
>>>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>               
>>>>>>>> Guillaume,
>>>>>>>>
>>>>>>>> Yes you are right, I did ask before (somehow I got sidetracked an
>>>>>>>> forgot
>>>>>>>> all
>>>>>>>> about it).  Anyway, thank you for the reply though.
>>>>>>>>
>>>>>>>> I have been able to implement a TcpComponentSupport class, at least
>>>>>>>> I
>>>>>>>> think
>>>>>>>> so anyway.  The problem that I am having now is that as soon as I
>>>>>>>> deploy
>>>>>>>> the
>>>>>>>> component it starts collecting data and pushing it to the bus.  I
>>>>>>>> have
>>>>>>>> run
>>>>>>>> into a couple of problems because of this.  The first problem is
>>>>>>>> while
>>>>>>>> testing, I would like to extend from TestSupport and use the
>>>>>>>> assertMessagesReceived(), however when it loads the
>>>>>>>> ApplicationContext,
>>>>>>>> the
>>>>>>>> concrete TcpComponentSupport class simply begins communicating over
>>>>>>>> the
>>>>>>>> socket and the test method with the assertMessagesReceived() call is
>>>>>>>> never
>>>>>>>> executed.  The test will just run forever.
>>>>>>>>
>>>>>>>> The second question that I have is along the same lines.  I would
>>>>>>>> like to
>>>>>>>> create a service unit, with simply this component in it and deploy
>>>>>>>> it to
>>>>>>>> ServiceMix and then use something like eip to route the messages
>>>>>>>> where I
>>>>>>>> want them.  The same kind of problem occurs in this scenario, as
>>>>>>>> soon as
>>>>>>>> the
>>>>>>>> service unit is deployed, it will start collecting data from the
>>>>>>>> stream
>>>>>>>> and
>>>>>>>> trying to push it to the bus, the problem is that there is no
>>>>>>>> destination
>>>>>>>> assigned to the the component yet so it tries to send it to
>>>>>>>> "service:
>>>>>>>> null
>>>>>>>> and interface null".
>>>>>>>>
>>>>>>>> Do you have any ideas?
>>>>>>>>
>>>>>>>> Thank you,
>>>>>>>> Doug
>>>>>>>>
>>>>>>>>
>>>>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>>>>
>>>>>>>>                 
>>>>>>>>> It seems there's none -- if I recall, you have already asked this
>>>>>>>>> question
>>>>>>>>> ;)
>>>>>>>>> However, it should not be very difficult to implement.
>>>>>>>>> You have to inherit the
>>>>>>>>> org.apache.servicemix.components.util.ComponentSupport and
>>>>>>>>> implements
>>>>>>>>> MessageExchangeListener.  Then, just create your socket and read it
>>>>>>>>> :)
>>>>>>>>> You may need another lw component for sending over tcp, also.
>>>>>>>>>
>>>>>>>>> Cheers,
>>>>>>>>> Guillaume Nodet
>>>>>>>>>
>>>>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>>>                   
>>>>>>>>>> Does anyone know if a basic TCP component is available?  What I
>>>>>>>>>> would
>>>>>>>>>> like
>>>>>>>>>> to be able to do is simply extend from a TCP component, set the
>>>>>>>>>> host
>>>>>>>>>> and
>>>>>>>>>> port in the servicemix.xml file, and have access to the input and
>>>>>>>>>> output
>>>>>>>>>> streams in my implementation class.  I would then want to be able
>>>>>>>>>> to
>>>>>>>>>> read
>>>>>>>>>> from the input stream and create a NormalizedMessage to put on the
>>>>>>>>>> bus
>>>>>>>>>> and
>>>>>>>>>> also be able to get a message from the bus and write it to the
>>>>>>>>>> output
>>>>>>>>>> stream.
>>>>>>>>>>
>>>>>>>>>> Is there anything like this out there?
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Doug
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>                     
>>>>>>>>
>>>>>>>>                 
>>>>>>
>>>>>>             
>>
>>
>>     
>
>   


Re: Basic TCP component

Posted by jpuro <jp...@sterlingtesting.com>.
Has a standard jbi BC component been created for this yet?  I think not, but
was curious.

-jeff


dfischer wrote:
> 
> Forget it, here is the code.  So sorry for so many emails.
> 
> 
> package org.apache.servicemix.components.tcp;
> 
> import org.apache.log4j.Logger;
> 
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.net.ConnectException;
> import java.net.InetSocketAddress;
> import java.net.Socket;
> import java.net.SocketException;
> import java.nio.channels.SocketChannel;
> 
> import javax.jbi.JBIException;
> import javax.jbi.messaging.InOnly;
> import javax.jbi.messaging.MessageExchange;
> import javax.jbi.messaging.MessagingException;
> import javax.jbi.messaging.NormalizedMessage;
> import javax.xml.transform.TransformerException;
> 
> import org.apache.servicemix.MessageExchangeListener;
> import org.apache.servicemix.components.util.ComponentSupport;
> import org.springframework.beans.factory.InitializingBean;
> 
> public abstract class TcpComponentSupport extends ComponentSupport
> implements
>         MessageExchangeListener, InitializingBean {
>     /**
>      * Logger for this class
>      */
>     private static final Logger log = Logger
>             .getLogger(TcpComponentSupport.class);
>     
>     private String host;
>     private int port = -1;
>     private boolean useNIO = false;
>     private int retryInterval = 10000;
>     protected SocketChannel socketChannel = null;
>     private Socket socket = null;
>     protected InputStream in = null;
>     protected OutputStream out = null;
>     protected boolean running = false;
>     private TcpMarshaler marshaler = new TcpMarshaler();
>     
>     protected abstract void processConnection() throws JBIException,
> IOException;
>     protected abstract void processIncomingMessage(String tcpMessage);
>     
>     public void setHost(String host) {
>         this.host = host;
>     } // en dof setHost(String)(
>     
>     public void setPort(int port) {
>         this.port = port;
>     } // en dof setPort(int)
>     
>     public void setUseNIO(boolean useNIO) {
>         this.useNIO = useNIO;
>     } // end of setUserNIO(boolean)
>     
>     public void setRetryInterval(int retryInterval) {
>         this.retryInterval = retryInterval;
>     } // end of setRetryInterval(int)
>     
>     protected boolean getUseNIO() {
>         return this.useNIO;
>     } // end of getUseNIO()
>     
>     protected String getHost() {
>         return this.host;
>     } // en dof getHost()
>     
>     protected int getPort() {
>         return this.port;
>     } // en dof getPort()
> 
>     public void onMessageExchange(MessageExchange exchange)
>             throws MessagingException {
>         String tcpMessage = null;
>         try {
>             tcpMessage =
> this.marshaler.fromNMS(exchange.getMessage("in"));
>             this.processIncomingMessage(tcpMessage);
>             this.done(exchange);
>         } catch (TransformerException e) {
>             throw new MessagingException(e);
>         } // end of try /catch
>     } // end of onMessageExchange(MessageExchange)
> 
>     public void afterPropertiesSet() throws Exception {
>         if (host == null) {
>             throw new IllegalArgumentException("You must specify the host
> property.");
>         } // end of if
>         
>         if (this.port < 0) {
>             throw new IllegalArgumentException("You must specify the port
> property.");
>         } // end of if
>     } // end of afterPropertiesSet()
>     
>     public void start() throws JBIException {
>         if (this.useNIO) {
>             // configure the NIO SocketChannel
>             this.startNIO();
>         } else {
>             // this is the default
>             // we will simply open a basic socket and create the Input and
> Ooutput Streams
>             this.startNonNIO();
>         } // end of if / else
>     } // end of start()
>     
>     public void stop() throws JBIException {
>         if (useNIO) {
>             this.stopNIO();
>         } else {
>             this.stopNonNIO();
>         } // ne do if / else
>     } // end of stop()
>     
>     protected void sendToBus(String message) {
>         log.debug("Inside sendToBus(), sending message: " + message);
>         try {
>             InOnly exchange =
> this.getExchangeFactory().createInOnlyExchange();
>             NormalizedMessage normalizedMessage =
> exchange.createMessage();
>             exchange.setInMessage(normalizedMessage);
>             this.marshaler.toNMS(normalizedMessage, message);
>             this.getDeliveryChannel().sendSync(exchange);
>             //done(exchange);
>         } catch (MessagingException me) {
>             throw new TcpConnectionException(me, message);
>         } // end of try / catch
>     } // end of sendToBus(String)
>     
>     /**
>      * This is an empty implementation of the init().
>      * This method exists so that the concrete class can override it
>      * if there is something that needs to be done to initialize the
> communication
>      * with the server.
>      * 
>      * This method is called after the connection has been made and after
> the 
>      * Input and Output Streams have been assigned.
>      * 
>      * This method is called right before the processConnection().
>      */
>     protected void init() {
>         // nothing is done here
>         // if something needs to be done here in the concrete class
>         // this method is called after the connection is made and the
> Input
> and Output Streams
>         // have been set but before the processConnection()
>     } // end of init()
>     
>     /**
>      * This is an empty implementation of the cleanup().
>      * 
>      * This method exists so the the concrete class can override it
>      * if there is something that needs to be done to cleanup resources
> before the 
>      * connection is shutdown.
>      * 
>      * This method is called while the connection is still active and the
> Input
>      * and Output Streams are still available.
>      */
>     protected void cleanup() {
>         // nothing is done here
>         // if something needs to be done here in the concrete class
>     } // end of init()
>     
>     private void startNIO() throws JBIException {
>         if (log.isInfoEnabled()) {
>             log.info("Using NIO to connect to " + this.host + ":" +
> this.port);
>         } // en dof if
> 
>         if (!this.running) {
>             this.connectNIO();
>             try {
>                 this.init();
>                 this.processConnection();
>             } catch (SocketException e) {
>                 this.running = false;
>                 this.startNIO();
>             } catch (IOException ioe) {
>                 throw new JBIException(ioe);
>             } // end of try / catch
>         } // end of if
>     } // end of startNIO()
>     
>     private void connectNIO() throws JBIException {
>         try {
>             this.socketChannel = SocketChannel.open();
>             this.socketChannel.configureBlocking(false);
>             
>             this.socketChannel.connect(new InetSocketAddress(this.host,
> this.port));
>             int count = 0;
>             while (!this.socketChannel.finishConnect()) {
>                 log.debug("Finishing connection: " + (count++) + "
> times");
>             } // end of while loop
>             
>             this.running = true;
>         } catch (ConnectException ce) {
>             log.warn(this.host + ":" + this.port + " unavailable, waiting
> "
> + this.retryInterval + " milliseconds before trying again.");
>             this.running = false;
>             try {
>                 Thread.sleep(this.retryInterval);
>             } catch (InterruptedException e) {}
>             this.connectNIO();
>         } catch (Exception e) {
>             log.error("Exception while trying to make a tcp connection to
> "
> + this.host + ":" + this.port);
>             log.error(e);
>             this.running = false;
>             throw new JBIException("Failed to connect to " + this.host +
> ":"
> + this.port, e);
>         } // end of try / catch
>     } // end of connectNIO()
>     
>     private void startNonNIO() throws JBIException {
>         if (log.isInfoEnabled()) {
>             log.info("Using basic sockets to connect to " + this.host +
> ":"
> + this.port);
>         } // en dof if
>         
>         if (!this.running) {
>             this.connectNonNIO();
>             try {
>                 this.init();
>                 this.processConnection();
>             } catch (SocketException e) {
>                 this.running = false;
>                 this.startNonNIO();
>             } catch (IOException ioe) {
>                 throw new JBIException(ioe);
>             } // end of try / catch
>         } // end of if
>     } // end of startNonNIO()
>     
>     private void connectNonNIO() throws JBIException {
>         try {
>             this.socket = new Socket(this.host, this.port);
>             
>             this.in = this.socket.getInputStream();
>             this.out = this.socket.getOutputStream();
>             
>             this.running = true;
>         } catch (ConnectException ce) {
>             log.warn(this.host + ":" + this.port + " unavailable, waiting
> "
> + this.retryInterval + " milliseconds before trying again.");
>             this.running = false;
>             try {
>                 Thread.sleep(this.retryInterval);
>             } catch (InterruptedException e) {}
>             this.connectNonNIO();
>         } catch (Exception e) {
>             log.error("Exception while trying to make a tcp connection to
> "
> + this.host + ":" + this.port);
>             log.error(e);
>             this.running = false;
>             throw new JBIException("Failed to connect to " + this.host +
> ":"
> + this.port, e);
>         } // end of try / catch
>     } // end of connectNonNIO()
>     
>     private void stopNIO() throws JBIException {
>         log.debug("Inside stopNIO()");
>         if (this.socketChannel != null) {
>             this.cleanup();
>             try {
>                 this.socketChannel.close();
>                 this.socketChannel = null;
>                 this.running = false;
>             } catch (IOException e) {
>                 throw new JBIException("Unable to close connection", e);
>             } // end of try / catch
>         } // end of if
>     } // end of stopNIO()
>     
>     private void stopNonNIO() throws JBIException {
>         log.debug("Inside stopNonNIO()");
>         if (this.socket != null) {
>             if (this.socket.isConnected()) {
>                 this.cleanup();
>                 try {
>                     this.socket.close();
>                     this.in = null;
>                     this.out = null;
>                     this.socket = null;
>                     this.running = false;
>                 } catch (IOException e) {
>                     throw new JBIException("Unable to close connection",
> e);
>                 } // end of try / catch
>             } // end of if
>         } // end of if
>     } // end of stopNonNIO()
> } // end of class TcpComponentSupport
> 
> 
> 
> On 5/12/06 11:49 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
> 
>> Sorry, let me try it again with just the .java file.
>> 
>> 
>> On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
>> 
>>> Hopefully this time the attachment will go through.  I am not exactly
>>> sure
>>> why it didn't before.  It is a zip file.
>>> 
>>> I guess I was thinking that when the component is deployed into the
>>> lwcontainer that it would be running in its own thread anyway. 
>>> Apparently I
>>> was incorrect in my assumption.
>>> 
>>> I am still trying to get a grasp on the whole ServiceMix thing so please
>>> excuse my ignorance.
>>> 
>>> Thanks,
>>> Doug
>>> 
>>> 
>>> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>> 
>>>> I think the attachment have been lost.
>>>> 
>>>> Btw, for a tcp consumer that creates a server socket, it has to wait
>>>> for incoming connections, so how can you not start a thread ? The
>>>> jabber api uses a listener, so it is really different.
>>>> 
>>>> Cheers,
>>>> Guillaume Nodet
>>>> 
>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>> I have attached my TcpComponentSupport class to this email.  If you
>>>>> could
>>>>> be
>>>>> so kind to take a look at it and let me know if it looks ok.  You
>>>>> mentioned
>>>>> that the start method should start a Thread and then kill that Thread
>>>>> in
>>>>> the
>>>>> stop method.  I am not actually doing this right now however I of
>>>>> course
>>>>> could implement it that way if necessary.  I attempted to use the
>>>>> JabberComponentSupport class as a template.
>>>>> 
>>>>> Please let me know your thoughts.
>>>>> 
>>>>> Thanks,
>>>>> Doug
>>>>> 
>>>>> 
>>>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>> 
>>>>>> Not sure to understand the problem.
>>>>>> Usually a lightweight consumer BC will begin to receive messages when
>>>>>> the component is started.  It means that all the necessary
>>>>>> configuration parameters have been set.
>>>>>> The tcp component needs to start a thread inside the start method
>>>>>> (and
>>>>>> kill it inside the stop method).
>>>>>> 
>>>>>> The second problem is related to components / service units
>>>>>> lifecycle.
>>>>>> When a lightweight component is deployed to the lwcontainer, he has a
>>>>>> specific lifecycle: when the service unit is started, the component
>>>>>> is
>>>>>> started and when the service unit is stopped, the component is
>>>>>> shutdown.
>>>>>> 
>>>>>> But the problem should only occur when someone sends something on the
>>>>>> socket
>>>>>> ...
>>>>>> 
>>>>>> Cheers,
>>>>>> Guillaume Nodet
>>>>>> 
>>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>> Guillaume,
>>>>>>> 
>>>>>>> Yes you are right, I did ask before (somehow I got sidetracked an
>>>>>>> forgot
>>>>>>> all
>>>>>>> about it).  Anyway, thank you for the reply though.
>>>>>>> 
>>>>>>> I have been able to implement a TcpComponentSupport class, at least
>>>>>>> I
>>>>>>> think
>>>>>>> so anyway.  The problem that I am having now is that as soon as I
>>>>>>> deploy
>>>>>>> the
>>>>>>> component it starts collecting data and pushing it to the bus.  I
>>>>>>> have
>>>>>>> run
>>>>>>> into a couple of problems because of this.  The first problem is
>>>>>>> while
>>>>>>> testing, I would like to extend from TestSupport and use the
>>>>>>> assertMessagesReceived(), however when it loads the
>>>>>>> ApplicationContext,
>>>>>>> the
>>>>>>> concrete TcpComponentSupport class simply begins communicating over
>>>>>>> the
>>>>>>> socket and the test method with the assertMessagesReceived() call is
>>>>>>> never
>>>>>>> executed.  The test will just run forever.
>>>>>>> 
>>>>>>> The second question that I have is along the same lines.  I would
>>>>>>> like to
>>>>>>> create a service unit, with simply this component in it and deploy
>>>>>>> it to
>>>>>>> ServiceMix and then use something like eip to route the messages
>>>>>>> where I
>>>>>>> want them.  The same kind of problem occurs in this scenario, as
>>>>>>> soon as
>>>>>>> the
>>>>>>> service unit is deployed, it will start collecting data from the
>>>>>>> stream
>>>>>>> and
>>>>>>> trying to push it to the bus, the problem is that there is no
>>>>>>> destination
>>>>>>> assigned to the the component yet so it tries to send it to
>>>>>>> "service:
>>>>>>> null
>>>>>>> and interface null".
>>>>>>> 
>>>>>>> Do you have any ideas?
>>>>>>> 
>>>>>>> Thank you,
>>>>>>> Doug
>>>>>>> 
>>>>>>> 
>>>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>>> 
>>>>>>>> It seems there's none -- if I recall, you have already asked this
>>>>>>>> question
>>>>>>>> ;)
>>>>>>>> However, it should not be very difficult to implement.
>>>>>>>> You have to inherit the
>>>>>>>> org.apache.servicemix.components.util.ComponentSupport and
>>>>>>>> implements
>>>>>>>> MessageExchangeListener.  Then, just create your socket and read it
>>>>>>>> :)
>>>>>>>> You may need another lw component for sending over tcp, also.
>>>>>>>> 
>>>>>>>> Cheers,
>>>>>>>> Guillaume Nodet
>>>>>>>> 
>>>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>>> Does anyone know if a basic TCP component is available?  What I
>>>>>>>>> would
>>>>>>>>> like
>>>>>>>>> to be able to do is simply extend from a TCP component, set the
>>>>>>>>> host
>>>>>>>>> and
>>>>>>>>> port in the servicemix.xml file, and have access to the input and
>>>>>>>>> output
>>>>>>>>> streams in my implementation class.  I would then want to be able
>>>>>>>>> to
>>>>>>>>> read
>>>>>>>>> from the input stream and create a NormalizedMessage to put on the
>>>>>>>>> bus
>>>>>>>>> and
>>>>>>>>> also be able to get a message from the bus and write it to the
>>>>>>>>> output
>>>>>>>>> stream.
>>>>>>>>> 
>>>>>>>>> Is there anything like this out there?
>>>>>>>>> 
>>>>>>>>> Thanks,
>>>>>>>>> Doug
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>> 
>> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Basic-TCP-component-tf1595103s12049.html#a13099933
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Basic TCP component

Posted by Doug Fischer <dg...@dfischer.com>.
Forget it, here is the code.  So sorry for so many emails.


package org.apache.servicemix.components.tcp;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.nio.channels.SocketChannel;

import javax.jbi.JBIException;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.transform.TransformerException;

import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.components.util.ComponentSupport;
import org.springframework.beans.factory.InitializingBean;

public abstract class TcpComponentSupport extends ComponentSupport
implements
        MessageExchangeListener, InitializingBean {
    /**
     * Logger for this class
     */
    private static final Logger log = Logger
            .getLogger(TcpComponentSupport.class);
    
    private String host;
    private int port = -1;
    private boolean useNIO = false;
    private int retryInterval = 10000;
    protected SocketChannel socketChannel = null;
    private Socket socket = null;
    protected InputStream in = null;
    protected OutputStream out = null;
    protected boolean running = false;
    private TcpMarshaler marshaler = new TcpMarshaler();
    
    protected abstract void processConnection() throws JBIException,
IOException;
    protected abstract void processIncomingMessage(String tcpMessage);
    
    public void setHost(String host) {
        this.host = host;
    } // en dof setHost(String)(
    
    public void setPort(int port) {
        this.port = port;
    } // en dof setPort(int)
    
    public void setUseNIO(boolean useNIO) {
        this.useNIO = useNIO;
    } // end of setUserNIO(boolean)
    
    public void setRetryInterval(int retryInterval) {
        this.retryInterval = retryInterval;
    } // end of setRetryInterval(int)
    
    protected boolean getUseNIO() {
        return this.useNIO;
    } // end of getUseNIO()
    
    protected String getHost() {
        return this.host;
    } // en dof getHost()
    
    protected int getPort() {
        return this.port;
    } // en dof getPort()

    public void onMessageExchange(MessageExchange exchange)
            throws MessagingException {
        String tcpMessage = null;
        try {
            tcpMessage = this.marshaler.fromNMS(exchange.getMessage("in"));
            this.processIncomingMessage(tcpMessage);
            this.done(exchange);
        } catch (TransformerException e) {
            throw new MessagingException(e);
        } // end of try /catch
    } // end of onMessageExchange(MessageExchange)

    public void afterPropertiesSet() throws Exception {
        if (host == null) {
            throw new IllegalArgumentException("You must specify the host
property.");
        } // end of if
        
        if (this.port < 0) {
            throw new IllegalArgumentException("You must specify the port
property.");
        } // end of if
    } // end of afterPropertiesSet()
    
    public void start() throws JBIException {
        if (this.useNIO) {
            // configure the NIO SocketChannel
            this.startNIO();
        } else {
            // this is the default
            // we will simply open a basic socket and create the Input and
Ooutput Streams
            this.startNonNIO();
        } // end of if / else
    } // end of start()
    
    public void stop() throws JBIException {
        if (useNIO) {
            this.stopNIO();
        } else {
            this.stopNonNIO();
        } // ne do if / else
    } // end of stop()
    
    protected void sendToBus(String message) {
        log.debug("Inside sendToBus(), sending message: " + message);
        try {
            InOnly exchange =
this.getExchangeFactory().createInOnlyExchange();
            NormalizedMessage normalizedMessage = exchange.createMessage();
            exchange.setInMessage(normalizedMessage);
            this.marshaler.toNMS(normalizedMessage, message);
            this.getDeliveryChannel().sendSync(exchange);
            //done(exchange);
        } catch (MessagingException me) {
            throw new TcpConnectionException(me, message);
        } // end of try / catch
    } // end of sendToBus(String)
    
    /**
     * This is an empty implementation of the init().
     * This method exists so that the concrete class can override it
     * if there is something that needs to be done to initialize the
communication
     * with the server.
     * 
     * This method is called after the connection has been made and after
the 
     * Input and Output Streams have been assigned.
     * 
     * This method is called right before the processConnection().
     */
    protected void init() {
        // nothing is done here
        // if something needs to be done here in the concrete class
        // this method is called after the connection is made and the Input
and Output Streams
        // have been set but before the processConnection()
    } // end of init()
    
    /**
     * This is an empty implementation of the cleanup().
     * 
     * This method exists so the the concrete class can override it
     * if there is something that needs to be done to cleanup resources
before the 
     * connection is shutdown.
     * 
     * This method is called while the connection is still active and the
Input
     * and Output Streams are still available.
     */
    protected void cleanup() {
        // nothing is done here
        // if something needs to be done here in the concrete class
    } // end of init()
    
    private void startNIO() throws JBIException {
        if (log.isInfoEnabled()) {
            log.info("Using NIO to connect to " + this.host + ":" +
this.port);
        } // en dof if

        if (!this.running) {
            this.connectNIO();
            try {
                this.init();
                this.processConnection();
            } catch (SocketException e) {
                this.running = false;
                this.startNIO();
            } catch (IOException ioe) {
                throw new JBIException(ioe);
            } // end of try / catch
        } // end of if
    } // end of startNIO()
    
    private void connectNIO() throws JBIException {
        try {
            this.socketChannel = SocketChannel.open();
            this.socketChannel.configureBlocking(false);
            
            this.socketChannel.connect(new InetSocketAddress(this.host,
this.port));
            int count = 0;
            while (!this.socketChannel.finishConnect()) {
                log.debug("Finishing connection: " + (count++) + " times");
            } // end of while loop
            
            this.running = true;
        } catch (ConnectException ce) {
            log.warn(this.host + ":" + this.port + " unavailable, waiting "
+ this.retryInterval + " milliseconds before trying again.");
            this.running = false;
            try {
                Thread.sleep(this.retryInterval);
            } catch (InterruptedException e) {}
            this.connectNIO();
        } catch (Exception e) {
            log.error("Exception while trying to make a tcp connection to "
+ this.host + ":" + this.port);
            log.error(e);
            this.running = false;
            throw new JBIException("Failed to connect to " + this.host + ":"
+ this.port, e);
        } // end of try / catch
    } // end of connectNIO()
    
    private void startNonNIO() throws JBIException {
        if (log.isInfoEnabled()) {
            log.info("Using basic sockets to connect to " + this.host + ":"
+ this.port);
        } // en dof if
        
        if (!this.running) {
            this.connectNonNIO();
            try {
                this.init();
                this.processConnection();
            } catch (SocketException e) {
                this.running = false;
                this.startNonNIO();
            } catch (IOException ioe) {
                throw new JBIException(ioe);
            } // end of try / catch
        } // end of if
    } // end of startNonNIO()
    
    private void connectNonNIO() throws JBIException {
        try {
            this.socket = new Socket(this.host, this.port);
            
            this.in = this.socket.getInputStream();
            this.out = this.socket.getOutputStream();
            
            this.running = true;
        } catch (ConnectException ce) {
            log.warn(this.host + ":" + this.port + " unavailable, waiting "
+ this.retryInterval + " milliseconds before trying again.");
            this.running = false;
            try {
                Thread.sleep(this.retryInterval);
            } catch (InterruptedException e) {}
            this.connectNonNIO();
        } catch (Exception e) {
            log.error("Exception while trying to make a tcp connection to "
+ this.host + ":" + this.port);
            log.error(e);
            this.running = false;
            throw new JBIException("Failed to connect to " + this.host + ":"
+ this.port, e);
        } // end of try / catch
    } // end of connectNonNIO()
    
    private void stopNIO() throws JBIException {
        log.debug("Inside stopNIO()");
        if (this.socketChannel != null) {
            this.cleanup();
            try {
                this.socketChannel.close();
                this.socketChannel = null;
                this.running = false;
            } catch (IOException e) {
                throw new JBIException("Unable to close connection", e);
            } // end of try / catch
        } // end of if
    } // end of stopNIO()
    
    private void stopNonNIO() throws JBIException {
        log.debug("Inside stopNonNIO()");
        if (this.socket != null) {
            if (this.socket.isConnected()) {
                this.cleanup();
                try {
                    this.socket.close();
                    this.in = null;
                    this.out = null;
                    this.socket = null;
                    this.running = false;
                } catch (IOException e) {
                    throw new JBIException("Unable to close connection", e);
                } // end of try / catch
            } // end of if
        } // end of if
    } // end of stopNonNIO()
} // end of class TcpComponentSupport



On 5/12/06 11:49 AM, "Doug Fischer" <dg...@dfischer.com> wrote:

> Sorry, let me try it again with just the .java file.
> 
> 
> On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:
> 
>> Hopefully this time the attachment will go through.  I am not exactly sure
>> why it didn't before.  It is a zip file.
>> 
>> I guess I was thinking that when the component is deployed into the
>> lwcontainer that it would be running in its own thread anyway.  Apparently I
>> was incorrect in my assumption.
>> 
>> I am still trying to get a grasp on the whole ServiceMix thing so please
>> excuse my ignorance.
>> 
>> Thanks,
>> Doug
>> 
>> 
>> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>> 
>>> I think the attachment have been lost.
>>> 
>>> Btw, for a tcp consumer that creates a server socket, it has to wait
>>> for incoming connections, so how can you not start a thread ? The
>>> jabber api uses a listener, so it is really different.
>>> 
>>> Cheers,
>>> Guillaume Nodet
>>> 
>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>> I have attached my TcpComponentSupport class to this email.  If you could
>>>> be
>>>> so kind to take a look at it and let me know if it looks ok.  You mentioned
>>>> that the start method should start a Thread and then kill that Thread in
>>>> the
>>>> stop method.  I am not actually doing this right now however I of course
>>>> could implement it that way if necessary.  I attempted to use the
>>>> JabberComponentSupport class as a template.
>>>> 
>>>> Please let me know your thoughts.
>>>> 
>>>> Thanks,
>>>> Doug
>>>> 
>>>> 
>>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>> 
>>>>> Not sure to understand the problem.
>>>>> Usually a lightweight consumer BC will begin to receive messages when
>>>>> the component is started.  It means that all the necessary
>>>>> configuration parameters have been set.
>>>>> The tcp component needs to start a thread inside the start method (and
>>>>> kill it inside the stop method).
>>>>> 
>>>>> The second problem is related to components / service units lifecycle.
>>>>> When a lightweight component is deployed to the lwcontainer, he has a
>>>>> specific lifecycle: when the service unit is started, the component is
>>>>> started and when the service unit is stopped, the component is
>>>>> shutdown.
>>>>> 
>>>>> But the problem should only occur when someone sends something on the
>>>>> socket
>>>>> ...
>>>>> 
>>>>> Cheers,
>>>>> Guillaume Nodet
>>>>> 
>>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>> Guillaume,
>>>>>> 
>>>>>> Yes you are right, I did ask before (somehow I got sidetracked an forgot
>>>>>> all
>>>>>> about it).  Anyway, thank you for the reply though.
>>>>>> 
>>>>>> I have been able to implement a TcpComponentSupport class, at least I
>>>>>> think
>>>>>> so anyway.  The problem that I am having now is that as soon as I deploy
>>>>>> the
>>>>>> component it starts collecting data and pushing it to the bus.  I have
>>>>>> run
>>>>>> into a couple of problems because of this.  The first problem is while
>>>>>> testing, I would like to extend from TestSupport and use the
>>>>>> assertMessagesReceived(), however when it loads the ApplicationContext,
>>>>>> the
>>>>>> concrete TcpComponentSupport class simply begins communicating over the
>>>>>> socket and the test method with the assertMessagesReceived() call is
>>>>>> never
>>>>>> executed.  The test will just run forever.
>>>>>> 
>>>>>> The second question that I have is along the same lines.  I would like to
>>>>>> create a service unit, with simply this component in it and deploy it to
>>>>>> ServiceMix and then use something like eip to route the messages where I
>>>>>> want them.  The same kind of problem occurs in this scenario, as soon as
>>>>>> the
>>>>>> service unit is deployed, it will start collecting data from the stream
>>>>>> and
>>>>>> trying to push it to the bus, the problem is that there is no destination
>>>>>> assigned to the the component yet so it tries to send it to "service:
>>>>>> null
>>>>>> and interface null".
>>>>>> 
>>>>>> Do you have any ideas?
>>>>>> 
>>>>>> Thank you,
>>>>>> Doug
>>>>>> 
>>>>>> 
>>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>>> 
>>>>>>> It seems there's none -- if I recall, you have already asked this
>>>>>>> question
>>>>>>> ;)
>>>>>>> However, it should not be very difficult to implement.
>>>>>>> You have to inherit the
>>>>>>> org.apache.servicemix.components.util.ComponentSupport and implements
>>>>>>> MessageExchangeListener.  Then, just create your socket and read it :)
>>>>>>> You may need another lw component for sending over tcp, also.
>>>>>>> 
>>>>>>> Cheers,
>>>>>>> Guillaume Nodet
>>>>>>> 
>>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>>> Does anyone know if a basic TCP component is available?  What I would
>>>>>>>> like
>>>>>>>> to be able to do is simply extend from a TCP component, set the host
>>>>>>>> and
>>>>>>>> port in the servicemix.xml file, and have access to the input and
>>>>>>>> output
>>>>>>>> streams in my implementation class.  I would then want to be able to
>>>>>>>> read
>>>>>>>> from the input stream and create a NormalizedMessage to put on the bus
>>>>>>>> and
>>>>>>>> also be able to get a message from the bus and write it to the output
>>>>>>>> stream.
>>>>>>>> 
>>>>>>>> Is there anything like this out there?
>>>>>>>> 
>>>>>>>> Thanks,
>>>>>>>> Doug
>>>>>>>> 
>>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>> 
>> 
> 



Re: Basic TCP component

Posted by Doug Fischer <dg...@dfischer.com>.
Sorry, let me try it again with just the .java file.


On 5/12/06 11:47 AM, "Doug Fischer" <dg...@dfischer.com> wrote:

> Hopefully this time the attachment will go through.  I am not exactly sure
> why it didn't before.  It is a zip file.
> 
> I guess I was thinking that when the component is deployed into the
> lwcontainer that it would be running in its own thread anyway.  Apparently I
> was incorrect in my assumption.
> 
> I am still trying to get a grasp on the whole ServiceMix thing so please
> excuse my ignorance.
> 
> Thanks,
> Doug
> 
> 
> On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> 
>> I think the attachment have been lost.
>> 
>> Btw, for a tcp consumer that creates a server socket, it has to wait
>> for incoming connections, so how can you not start a thread ? The
>> jabber api uses a listener, so it is really different.
>> 
>> Cheers,
>> Guillaume Nodet
>> 
>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>> I have attached my TcpComponentSupport class to this email.  If you could be
>>> so kind to take a look at it and let me know if it looks ok.  You mentioned
>>> that the start method should start a Thread and then kill that Thread in the
>>> stop method.  I am not actually doing this right now however I of course
>>> could implement it that way if necessary.  I attempted to use the
>>> JabberComponentSupport class as a template.
>>> 
>>> Please let me know your thoughts.
>>> 
>>> Thanks,
>>> Doug
>>> 
>>> 
>>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>> 
>>>> Not sure to understand the problem.
>>>> Usually a lightweight consumer BC will begin to receive messages when
>>>> the component is started.  It means that all the necessary
>>>> configuration parameters have been set.
>>>> The tcp component needs to start a thread inside the start method (and
>>>> kill it inside the stop method).
>>>> 
>>>> The second problem is related to components / service units lifecycle.
>>>> When a lightweight component is deployed to the lwcontainer, he has a
>>>> specific lifecycle: when the service unit is started, the component is
>>>> started and when the service unit is stopped, the component is
>>>> shutdown.
>>>> 
>>>> But the problem should only occur when someone sends something on the
>>>> socket
>>>> ...
>>>> 
>>>> Cheers,
>>>> Guillaume Nodet
>>>> 
>>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>> Guillaume,
>>>>> 
>>>>> Yes you are right, I did ask before (somehow I got sidetracked an forgot
>>>>> all
>>>>> about it).  Anyway, thank you for the reply though.
>>>>> 
>>>>> I have been able to implement a TcpComponentSupport class, at least I
>>>>> think
>>>>> so anyway.  The problem that I am having now is that as soon as I deploy
>>>>> the
>>>>> component it starts collecting data and pushing it to the bus.  I have run
>>>>> into a couple of problems because of this.  The first problem is while
>>>>> testing, I would like to extend from TestSupport and use the
>>>>> assertMessagesReceived(), however when it loads the ApplicationContext,
>>>>> the
>>>>> concrete TcpComponentSupport class simply begins communicating over the
>>>>> socket and the test method with the assertMessagesReceived() call is never
>>>>> executed.  The test will just run forever.
>>>>> 
>>>>> The second question that I have is along the same lines.  I would like to
>>>>> create a service unit, with simply this component in it and deploy it to
>>>>> ServiceMix and then use something like eip to route the messages where I
>>>>> want them.  The same kind of problem occurs in this scenario, as soon as
>>>>> the
>>>>> service unit is deployed, it will start collecting data from the stream
>>>>> and
>>>>> trying to push it to the bus, the problem is that there is no destination
>>>>> assigned to the the component yet so it tries to send it to "service: null
>>>>> and interface null".
>>>>> 
>>>>> Do you have any ideas?
>>>>> 
>>>>> Thank you,
>>>>> Doug
>>>>> 
>>>>> 
>>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>>> 
>>>>>> It seems there's none -- if I recall, you have already asked this
>>>>>> question
>>>>>> ;)
>>>>>> However, it should not be very difficult to implement.
>>>>>> You have to inherit the
>>>>>> org.apache.servicemix.components.util.ComponentSupport and implements
>>>>>> MessageExchangeListener.  Then, just create your socket and read it :)
>>>>>> You may need another lw component for sending over tcp, also.
>>>>>> 
>>>>>> Cheers,
>>>>>> Guillaume Nodet
>>>>>> 
>>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>>> Does anyone know if a basic TCP component is available?  What I would
>>>>>>> like
>>>>>>> to be able to do is simply extend from a TCP component, set the host and
>>>>>>> port in the servicemix.xml file, and have access to the input and output
>>>>>>> streams in my implementation class.  I would then want to be able to
>>>>>>> read
>>>>>>> from the input stream and create a NormalizedMessage to put on the bus
>>>>>>> and
>>>>>>> also be able to get a message from the bus and write it to the output
>>>>>>> stream.
>>>>>>> 
>>>>>>> Is there anything like this out there?
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> Doug
>>>>>>> 
>>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>> 
>>> 
>>> 
>> 
> 


Re: Basic TCP component

Posted by Doug Fischer <dg...@dfischer.com>.
Hopefully this time the attachment will go through.  I am not exactly sure
why it didn't before.  It is a zip file.

I guess I was thinking that when the component is deployed into the
lwcontainer that it would be running in its own thread anyway.  Apparently I
was incorrect in my assumption.

I am still trying to get a grasp on the whole ServiceMix thing so please
excuse my ignorance.

Thanks,
Doug


On 5/12/06 11:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:

> I think the attachment have been lost.
> 
> Btw, for a tcp consumer that creates a server socket, it has to wait
> for incoming connections, so how can you not start a thread ? The
> jabber api uses a listener, so it is really different.
> 
> Cheers,
> Guillaume Nodet
> 
> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>> I have attached my TcpComponentSupport class to this email.  If you could be
>> so kind to take a look at it and let me know if it looks ok.  You mentioned
>> that the start method should start a Thread and then kill that Thread in the
>> stop method.  I am not actually doing this right now however I of course
>> could implement it that way if necessary.  I attempted to use the
>> JabberComponentSupport class as a template.
>> 
>> Please let me know your thoughts.
>> 
>> Thanks,
>> Doug
>> 
>> 
>> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>> 
>>> Not sure to understand the problem.
>>> Usually a lightweight consumer BC will begin to receive messages when
>>> the component is started.  It means that all the necessary
>>> configuration parameters have been set.
>>> The tcp component needs to start a thread inside the start method (and
>>> kill it inside the stop method).
>>> 
>>> The second problem is related to components / service units lifecycle.
>>> When a lightweight component is deployed to the lwcontainer, he has a
>>> specific lifecycle: when the service unit is started, the component is
>>> started and when the service unit is stopped, the component is
>>> shutdown.
>>> 
>>> But the problem should only occur when someone sends something on the socket
>>> ...
>>> 
>>> Cheers,
>>> Guillaume Nodet
>>> 
>>> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>> Guillaume,
>>>> 
>>>> Yes you are right, I did ask before (somehow I got sidetracked an forgot
>>>> all
>>>> about it).  Anyway, thank you for the reply though.
>>>> 
>>>> I have been able to implement a TcpComponentSupport class, at least I think
>>>> so anyway.  The problem that I am having now is that as soon as I deploy
>>>> the
>>>> component it starts collecting data and pushing it to the bus.  I have run
>>>> into a couple of problems because of this.  The first problem is while
>>>> testing, I would like to extend from TestSupport and use the
>>>> assertMessagesReceived(), however when it loads the ApplicationContext, the
>>>> concrete TcpComponentSupport class simply begins communicating over the
>>>> socket and the test method with the assertMessagesReceived() call is never
>>>> executed.  The test will just run forever.
>>>> 
>>>> The second question that I have is along the same lines.  I would like to
>>>> create a service unit, with simply this component in it and deploy it to
>>>> ServiceMix and then use something like eip to route the messages where I
>>>> want them.  The same kind of problem occurs in this scenario, as soon as
>>>> the
>>>> service unit is deployed, it will start collecting data from the stream and
>>>> trying to push it to the bus, the problem is that there is no destination
>>>> assigned to the the component yet so it tries to send it to "service: null
>>>> and interface null".
>>>> 
>>>> Do you have any ideas?
>>>> 
>>>> Thank you,
>>>> Doug
>>>> 
>>>> 
>>>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>>>> 
>>>>> It seems there's none -- if I recall, you have already asked this question
>>>>> ;)
>>>>> However, it should not be very difficult to implement.
>>>>> You have to inherit the
>>>>> org.apache.servicemix.components.util.ComponentSupport and implements
>>>>> MessageExchangeListener.  Then, just create your socket and read it :)
>>>>> You may need another lw component for sending over tcp, also.
>>>>> 
>>>>> Cheers,
>>>>> Guillaume Nodet
>>>>> 
>>>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>>>> Does anyone know if a basic TCP component is available?  What I would
>>>>>> like
>>>>>> to be able to do is simply extend from a TCP component, set the host and
>>>>>> port in the servicemix.xml file, and have access to the input and output
>>>>>> streams in my implementation class.  I would then want to be able to read
>>>>>> from the input stream and create a NormalizedMessage to put on the bus
>>>>>> and
>>>>>> also be able to get a message from the bus and write it to the output
>>>>>> stream.
>>>>>> 
>>>>>> Is there anything like this out there?
>>>>>> 
>>>>>> Thanks,
>>>>>> Doug
>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>> 
>> 
>> 
>> 
> 


Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
I think the attachment have been lost.

Btw, for a tcp consumer that creates a server socket, it has to wait
for incoming connections, so how can you not start a thread ? The
jabber api uses a listener, so it is really different.

Cheers,
Guillaume Nodet

On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> I have attached my TcpComponentSupport class to this email.  If you could be
> so kind to take a look at it and let me know if it looks ok.  You mentioned
> that the start method should start a Thread and then kill that Thread in the
> stop method.  I am not actually doing this right now however I of course
> could implement it that way if necessary.  I attempted to use the
> JabberComponentSupport class as a template.
>
> Please let me know your thoughts.
>
> Thanks,
> Doug
>
>
> On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>
> > Not sure to understand the problem.
> > Usually a lightweight consumer BC will begin to receive messages when
> > the component is started.  It means that all the necessary
> > configuration parameters have been set.
> > The tcp component needs to start a thread inside the start method (and
> > kill it inside the stop method).
> >
> > The second problem is related to components / service units lifecycle.
> > When a lightweight component is deployed to the lwcontainer, he has a
> > specific lifecycle: when the service unit is started, the component is
> > started and when the service unit is stopped, the component is
> > shutdown.
> >
> > But the problem should only occur when someone sends something on the socket
> > ...
> >
> > Cheers,
> > Guillaume Nodet
> >
> > On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> >> Guillaume,
> >>
> >> Yes you are right, I did ask before (somehow I got sidetracked an forgot all
> >> about it).  Anyway, thank you for the reply though.
> >>
> >> I have been able to implement a TcpComponentSupport class, at least I think
> >> so anyway.  The problem that I am having now is that as soon as I deploy the
> >> component it starts collecting data and pushing it to the bus.  I have run
> >> into a couple of problems because of this.  The first problem is while
> >> testing, I would like to extend from TestSupport and use the
> >> assertMessagesReceived(), however when it loads the ApplicationContext, the
> >> concrete TcpComponentSupport class simply begins communicating over the
> >> socket and the test method with the assertMessagesReceived() call is never
> >> executed.  The test will just run forever.
> >>
> >> The second question that I have is along the same lines.  I would like to
> >> create a service unit, with simply this component in it and deploy it to
> >> ServiceMix and then use something like eip to route the messages where I
> >> want them.  The same kind of problem occurs in this scenario, as soon as the
> >> service unit is deployed, it will start collecting data from the stream and
> >> trying to push it to the bus, the problem is that there is no destination
> >> assigned to the the component yet so it tries to send it to "service: null
> >> and interface null".
> >>
> >> Do you have any ideas?
> >>
> >> Thank you,
> >> Doug
> >>
> >>
> >> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
> >>
> >>> It seems there's none -- if I recall, you have already asked this question
> >>> ;)
> >>> However, it should not be very difficult to implement.
> >>> You have to inherit the
> >>> org.apache.servicemix.components.util.ComponentSupport and implements
> >>> MessageExchangeListener.  Then, just create your socket and read it :)
> >>> You may need another lw component for sending over tcp, also.
> >>>
> >>> Cheers,
> >>> Guillaume Nodet
> >>>
> >>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
> >>>> Does anyone know if a basic TCP component is available?  What I would like
> >>>> to be able to do is simply extend from a TCP component, set the host and
> >>>> port in the servicemix.xml file, and have access to the input and output
> >>>> streams in my implementation class.  I would then want to be able to read
> >>>> from the input stream and create a NormalizedMessage to put on the bus and
> >>>> also be able to get a message from the bus and write it to the output
> >>>> stream.
> >>>>
> >>>> Is there anything like this out there?
> >>>>
> >>>> Thanks,
> >>>> Doug
> >>>>
> >>>>
> >>>
> >>
> >>
> >>
> >
>
>
>

Re: Basic TCP component

Posted by Doug Fischer <dg...@dfischer.com>.
I have attached my TcpComponentSupport class to this email.  If you could be
so kind to take a look at it and let me know if it looks ok.  You mentioned
that the start method should start a Thread and then kill that Thread in the
stop method.  I am not actually doing this right now however I of course
could implement it that way if necessary.  I attempted to use the
JabberComponentSupport class as a template.

Please let me know your thoughts.

Thanks,
Doug


On 5/12/06 8:06 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:

> Not sure to understand the problem.
> Usually a lightweight consumer BC will begin to receive messages when
> the component is started.  It means that all the necessary
> configuration parameters have been set.
> The tcp component needs to start a thread inside the start method (and
> kill it inside the stop method).
> 
> The second problem is related to components / service units lifecycle.
> When a lightweight component is deployed to the lwcontainer, he has a
> specific lifecycle: when the service unit is started, the component is
> started and when the service unit is stopped, the component is
> shutdown.
> 
> But the problem should only occur when someone sends something on the socket
> ...
> 
> Cheers,
> Guillaume Nodet
> 
> On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
>> Guillaume,
>> 
>> Yes you are right, I did ask before (somehow I got sidetracked an forgot all
>> about it).  Anyway, thank you for the reply though.
>> 
>> I have been able to implement a TcpComponentSupport class, at least I think
>> so anyway.  The problem that I am having now is that as soon as I deploy the
>> component it starts collecting data and pushing it to the bus.  I have run
>> into a couple of problems because of this.  The first problem is while
>> testing, I would like to extend from TestSupport and use the
>> assertMessagesReceived(), however when it loads the ApplicationContext, the
>> concrete TcpComponentSupport class simply begins communicating over the
>> socket and the test method with the assertMessagesReceived() call is never
>> executed.  The test will just run forever.
>> 
>> The second question that I have is along the same lines.  I would like to
>> create a service unit, with simply this component in it and deploy it to
>> ServiceMix and then use something like eip to route the messages where I
>> want them.  The same kind of problem occurs in this scenario, as soon as the
>> service unit is deployed, it will start collecting data from the stream and
>> trying to push it to the bus, the problem is that there is no destination
>> assigned to the the component yet so it tries to send it to "service: null
>> and interface null".
>> 
>> Do you have any ideas?
>> 
>> Thank you,
>> Doug
>> 
>> 
>> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>> 
>>> It seems there's none -- if I recall, you have already asked this question
>>> ;)
>>> However, it should not be very difficult to implement.
>>> You have to inherit the
>>> org.apache.servicemix.components.util.ComponentSupport and implements
>>> MessageExchangeListener.  Then, just create your socket and read it :)
>>> You may need another lw component for sending over tcp, also.
>>> 
>>> Cheers,
>>> Guillaume Nodet
>>> 
>>> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>>>> Does anyone know if a basic TCP component is available?  What I would like
>>>> to be able to do is simply extend from a TCP component, set the host and
>>>> port in the servicemix.xml file, and have access to the input and output
>>>> streams in my implementation class.  I would then want to be able to read
>>>> from the input stream and create a NormalizedMessage to put on the bus and
>>>> also be able to get a message from the bus and write it to the output
>>>> stream.
>>>> 
>>>> Is there anything like this out there?
>>>> 
>>>> Thanks,
>>>> Doug
>>>> 
>>>> 
>>> 
>> 
>> 
>> 
> 


Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
Not sure to understand the problem.
Usually a lightweight consumer BC will begin to receive messages when
the component is started.  It means that all the necessary
configuration parameters have been set.
The tcp component needs to start a thread inside the start method (and
kill it inside the stop method).

The second problem is related to components / service units lifecycle.
When a lightweight component is deployed to the lwcontainer, he has a
specific lifecycle: when the service unit is started, the component is
started and when the service unit is stopped, the component is
shutdown.

But the problem should only occur when someone sends something on the socket ...

Cheers,
Guillaume Nodet

On 5/12/06, Doug Fischer <dg...@dfischer.com> wrote:
> Guillaume,
>
> Yes you are right, I did ask before (somehow I got sidetracked an forgot all
> about it).  Anyway, thank you for the reply though.
>
> I have been able to implement a TcpComponentSupport class, at least I think
> so anyway.  The problem that I am having now is that as soon as I deploy the
> component it starts collecting data and pushing it to the bus.  I have run
> into a couple of problems because of this.  The first problem is while
> testing, I would like to extend from TestSupport and use the
> assertMessagesReceived(), however when it loads the ApplicationContext, the
> concrete TcpComponentSupport class simply begins communicating over the
> socket and the test method with the assertMessagesReceived() call is never
> executed.  The test will just run forever.
>
> The second question that I have is along the same lines.  I would like to
> create a service unit, with simply this component in it and deploy it to
> ServiceMix and then use something like eip to route the messages where I
> want them.  The same kind of problem occurs in this scenario, as soon as the
> service unit is deployed, it will start collecting data from the stream and
> trying to push it to the bus, the problem is that there is no destination
> assigned to the the component yet so it tries to send it to "service: null
> and interface null".
>
> Do you have any ideas?
>
> Thank you,
> Doug
>
>
> On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:
>
> > It seems there's none -- if I recall, you have already asked this question ;)
> > However, it should not be very difficult to implement.
> > You have to inherit the
> > org.apache.servicemix.components.util.ComponentSupport and implements
> > MessageExchangeListener.  Then, just create your socket and read it :)
> > You may need another lw component for sending over tcp, also.
> >
> > Cheers,
> > Guillaume Nodet
> >
> > On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
> >> Does anyone know if a basic TCP component is available?  What I would like
> >> to be able to do is simply extend from a TCP component, set the host and
> >> port in the servicemix.xml file, and have access to the input and output
> >> streams in my implementation class.  I would then want to be able to read
> >> from the input stream and create a NormalizedMessage to put on the bus and
> >> also be able to get a message from the bus and write it to the output
> >> stream.
> >>
> >> Is there anything like this out there?
> >>
> >> Thanks,
> >> Doug
> >>
> >>
> >
>
>
>

Re: Basic TCP component

Posted by Doug Fischer <dg...@dfischer.com>.
Guillaume,

Yes you are right, I did ask before (somehow I got sidetracked an forgot all
about it).  Anyway, thank you for the reply though.

I have been able to implement a TcpComponentSupport class, at least I think
so anyway.  The problem that I am having now is that as soon as I deploy the
component it starts collecting data and pushing it to the bus.  I have run
into a couple of problems because of this.  The first problem is while
testing, I would like to extend from TestSupport and use the
assertMessagesReceived(), however when it loads the ApplicationContext, the
concrete TcpComponentSupport class simply begins communicating over the
socket and the test method with the assertMessagesReceived() call is never
executed.  The test will just run forever.

The second question that I have is along the same lines.  I would like to
create a service unit, with simply this component in it and deploy it to
ServiceMix and then use something like eip to route the messages where I
want them.  The same kind of problem occurs in this scenario, as soon as the
service unit is deployed, it will start collecting data from the stream and
trying to push it to the bus, the problem is that there is no destination
assigned to the the component yet so it tries to send it to "service: null
and interface null".

Do you have any ideas?

Thank you,
Doug


On 5/11/06 3:19 AM, "Guillaume Nodet" <gn...@gmail.com> wrote:

> It seems there's none -- if I recall, you have already asked this question ;)
> However, it should not be very difficult to implement.
> You have to inherit the
> org.apache.servicemix.components.util.ComponentSupport and implements
> MessageExchangeListener.  Then, just create your socket and read it :)
> You may need another lw component for sending over tcp, also.
> 
> Cheers,
> Guillaume Nodet
> 
> On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
>> Does anyone know if a basic TCP component is available?  What I would like
>> to be able to do is simply extend from a TCP component, set the host and
>> port in the servicemix.xml file, and have access to the input and output
>> streams in my implementation class.  I would then want to be able to read
>> from the input stream and create a NormalizedMessage to put on the bus and
>> also be able to get a message from the bus and write it to the output
>> stream.
>> 
>> Is there anything like this out there?
>> 
>> Thanks,
>> Doug
>> 
>> 
> 



Re: Basic TCP component

Posted by Guillaume Nodet <gn...@gmail.com>.
It seems there's none -- if I recall, you have already asked this question ;)
However, it should not be very difficult to implement.
You have to inherit the
org.apache.servicemix.components.util.ComponentSupport and implements
MessageExchangeListener.  Then, just create your socket and read it :)
You may need another lw component for sending over tcp, also.

Cheers,
Guillaume Nodet

On 5/10/06, Doug Fischer <dg...@dfischer.com> wrote:
> Does anyone know if a basic TCP component is available?  What I would like
> to be able to do is simply extend from a TCP component, set the host and
> port in the servicemix.xml file, and have access to the input and output
> streams in my implementation class.  I would then want to be able to read
> from the input stream and create a NormalizedMessage to put on the bus and
> also be able to get a message from the bus and write it to the output
> stream.
>
> Is there anything like this out there?
>
> Thanks,
> Doug
>
>