synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Davanum Srinivas" <dava...@gmail.com>
Subject Re: Mediator init and destroy
Date Thu, 26 Jul 2007 14:31:35 GMT
Paul,

How about a mechanism for synapse to tell GMondPuller to shut itself
down as Synapse instance itslef is being shutdown?

thanks,
dims

On 7/26/07, Paul Fremantle <pzfreo@gmail.com> wrote:
> Here is a simple example of what I'd like to be able to do
>
> As you can see it would make it dead simple to add a new adapter. In
> this case, all you need to do to get XML from gmond is to open a
> socket to it.
>
> The changes we'd need to make this work are:
>
> 1) create a synapse interface Initializable which could be implemented
> both by mediators and also by stuff like adapters that need to be run
> but aren't mediators
> 2) Add a way of specifying things that need to be started in the Synapse config:
>
> e.g.
> <startup>
>    <init class="org.fremantle.GMondPuller"/>
> </startup>
>
> 2) need to be able to get at the thread pool from the
> SynapseEnvironment (this could just be a link into the Axis2 thread
> pool)
> 3) Fix createMessageContext!
> 4) I think that is it.
>
> public class GMondPuller implements Initializable, Runnable {
>
>         private String hostName = null;
>         private int port = 0;
>         private long interval = 1000;
>         private SynapseEnvironment synapseEnvironment = null;
>
>         public void init(SynapseConfiguration sc, SynapseEnvironment se) {
>                 synapseEnvironment = se;
>                 synapseEnvironment.getThreadPool().execute(this);
>         }
>
>         public void run() {
>
>                 if (hostName == null || port == 0 || synapseEnvironment == null)
>                         return;
>                 try {
>                         while (true) {
>                                 java.net.Socket socket = new Socket(hostName, port);
>                                 StAXOMBuilder builder = new StAXOMBuilder(socket
>                                                 .getInputStream());
>                                 MessageContext mc =
>                                      synapseEnvironment.createMessageContext();
>                                 mc.getEnvelope().getBody().addChild(builder.getDocumentElement());
>                                 synapseEnvironment.injectMessage(mc);
>                                 Thread.sleep(interval);
>                         }
>                 } catch (Exception e) {
>                         log.debug(e);
>                 }
>
>         }
>
>         public void setHostName(String hostName) {
>                 this.hostName = hostName;
>         }
>
>         public String getHostName() {
>                 return hostName;
>         }
>
>         public void setPort(int port) {
>                 this.port = port;
>         }
>
>         public int getPort() {
>                 return port;
>         }
>
>         public void setInterval(long interval) {
>                 this.interval = interval;
>         }
>
>         public long getInterval() {
>                 return interval;
>         }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: synapse-dev-help@ws.apache.org
>
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message