+1, although I have no idea what that should look like.

On Mon, May 25, 2009 at 7:14 AM, Lenni Madsen <[email protected]> wrote:
> I'll bet it's related to that thread, could we once and for all agree that
> the current wsn-producer example is providing more issues than it helps
> remove.
>
> Guys, in the wsn-producer example from Muse there's a thread used, this is
> used ONLY to make the example run continuesly. The thread is not needed for
> a production version and is not in all the examples I've posted last week.
>
> I'll see if I can't cook up something
>
> On 25/05/2009, at 06.36, Chris Twiner <[email protected]> wrote:
>
>> Sorry, but could you please give more details of what doesn't work?
>> For example, log files, stack traces, messages sent etc.
>>
>> On Mon, May 25, 2009 at 5:16 AM, ciel <[email protected]> wrote:
>>>
>>> I have not solved the problem yet.
>>> my MyCapability's is as follows and I didn't change wsn-consumer' code
>>>
>>> package org.apache.ws.muse.test.wsrf;
>>>
>>> import java.io.File;
>>> import java.io.IOException;
>>>
>>> import javax.xml.namespace.QName;
>>> import javax.xml.parsers.DocumentBuilder;
>>> import javax.xml.parsers.DocumentBuilderFactory;
>>> import javax.xml.parsers.ParserConfigurationException;
>>>
>>> import org.apache.muse.ws.addressing.soap.SoapFault;
>>> import org.apache.muse.ws.dm.muws.events.Component;
>>> import org.apache.muse.ws.dm.muws.events.ComponentAddress;
>>> import org.apache.muse.ws.dm.muws.events.ManagementEvent;
>>> import org.apache.muse.ws.dm.muws.events.Situation;
>>> import org.apache.muse.ws.dm.muws.events.WefConstants;
>>> import org.apache.muse.ws.dm.muws.events.WefFactory;
>>> import org.apache.muse.ws.dm.muws.events.impl.SimpleWefFactory;
>>> import org.apache.muse.ws.notification.NotificationProducer;
>>> import org.apache.muse.ws.notification.WsnConstants;
>>> import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
>>> import org.w3c.dom.Document;
>>> import org.w3c.dom.Element;
>>> import org.xml.sax.SAXException;
>>>
>>> public class MyCapabilityImpl extends AbstractWsResourceCapability
>>> implements MyCapability
>>> {
>>>   private static final QName[] _PROPERTIES = new QName[] {
>>>           new QName(NAMESPACE_URI, "MessageInterval", PREFIX),
>>>           new QName(NAMESPACE_URI, "ServerName", PREFIX)
>>>   };
>>>
>>>   private static final QName _TOPIC_NAME = new QName(NAMESPACE_URI,
>>> "MyTopic", PREFIX);
>>>
>>>   public QName[] getPropertyNames()
>>>   {
>>>       return _PROPERTIES;
>>>   }
>>>
>>>   private int _MessageInterval = 10;
>>>
>>>   private String _ServerName = "muse-test.apache.org";
>>>
>>>   public int getMessageInterval()
>>>   {
>>>       return _MessageInterval;
>>>   }
>>>
>>>   public void setMessageInterval(int param0)
>>>   {
>>>       _MessageInterval = param0;
>>>   }
>>>
>>>   public String getServerName()
>>>   {
>>>       return _ServerName;
>>>   }
>>>
>>>   public void setServerName(String param0)
>>>   {
>>>       _ServerName = param0;
>>>   }
>>>
>>>   public void initializeCompleted()
>>>       throws SoapFault
>>>   {
>>>       super.initializeCompleted();
>>>
>>>       //
>>>       // access resource's WSN capability and create a new topic
>>>       //
>>>       final NotificationProducer wsn =
>>>
>>> (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
>>>       wsn.addTopic(_TOPIC_NAME);
>>>
>>>       Thread producer = new Thread() {
>>>           public void run()
>>>           {
>>>               //
>>>               // for this example, reuse one payload for every
>>> notification
>>>               //
>>>               QName messageName = new QName(NAMESPACE_URI, "MyMessage",
>>> PREFIX);
>>>               try
>>>               {
>>>                       payload = runtimeEventOperation();
>>>               }
>>>               catch (Exception e)
>>>               {
>>>                       e.printStackTrace();
>>>               }
>>>
>>>               while (true)
>>>               {
>>>                   try
>>>                   {
>>>                       //
>>>                       // read current value - property is mutable
>>>                       //
>>>                       int currentInterval = getMessageInterval();
>>> //                        System.out.println(payload);
>>>
>>>                       getLog().info("Waiting " + currentInterval + "
>>> seconds before sending message...");
>>>                       Thread.currentThread().sleep(currentInterval *
>>> 1000);
>>>
>>>                       //
>>>                       // use WSN capability to send message to any
>>> subscribers
>>>                       //
>>>                       getLog().info("Sending message to consumers...");
>>>                       wsn.publish(_TOPIC_NAME, payload);
>>>                   }
>>>
>>>                   catch (Throwable error)
>>>                   {
>>>                       error.printStackTrace();
>>>                   }
>>>               }
>>>           }
>>>       };
>>>       producer.start();
>>>   }
>>>   private static ManagementEvent payload;
>>>   public ManagementEvent runtimeEventOperation() throws Exception{
>>>       WefFactory factory = new SimpleWefFactory();
>>>       ManagementEvent event = factory.createEvent();
>>>
>>>       Component reporter = factory.createComponent();
>>>       ComponentAddress reporterAddress =
>>>
>>> factory.createComponentAddress(getResource().getEndpointReference().toXML());
>>>       reporter.setAddress(reporterAddress);
>>>       reporter.setName(WefConstants.REPORTER_COMP_QNAME);
>>>
>>>       Component source = factory.createComponent();
>>>       ComponentAddress sourceAddress =
>>>
>>> factory.createComponentAddress(getResource().getEndpointReference().toXML());
>>>       source.setAddress(sourceAddress);
>>>       source.setName(WefConstants.SOURCE_COMP_QNAME);
>>>
>>>       Situation situation = factory.createSituation();
>>>
>>> situation.setCategoryType(WefConstants.AVAILABILITY_SITUATION_QNAME);
>>>       situation.setPriority(Situation.HIGH_PRIORITY);
>>>       situation.setMessage("Something important has happened in the
>>> "+getServerName()+"!");
>>>       event.setReporter(reporter);
>>>       event.setSource(source);
>>>       event.setSituation(situation);
>>>
>>>       event.addExtendedElement(MessageExtension());
>>>       return event;
>>> //        try{
>>> //                getLog().info("Sending message to consumers...");
>>> //                runtimeNotification.publish(_TOPIC_NAME, event);
>>> //                }
>>> //        catch (Throwable error){
>>> //                        error.printStackTrace();
>>> //                        }
>>> //        return event.toXML();
>>>      }
>>>
>>>      private Element MessageExtension()throws
>>> ParserConfigurationException, SAXException, IOException{
>>>       // create your XML message
>>>
>>>        File file = new
>>> File("E:/Awork/java/jakarta-tomcat-5.0.28/temp","test.xml");
>>>          DocumentBuilderFactory   dbf   =
>>> DocumentBuilderFactory.newInstance();
>>>          DocumentBuilder   db   =   dbf.newDocumentBuilder();
>>>          Document   doc   =   db.parse(file);
>>>          doc.normalize();
>>>          Element   root   =   doc.getDocumentElement();
>>>          return root;
>>>      }
>>> }
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Transport-my-own-data-types--form-wsn-producer-to-wsn-consumer-tp23631392p23700618.html
>>> Sent from the Muse User mailing list archive at Nabble.com.
>>>
>>>
>

Reply via email to