Package org.wso2.carbon.event.broker.pubsub

Source Code of org.wso2.carbon.event.broker.pubsub.NonCarbonPubSubTest

package org.wso2.carbon.event.broker.pubsub;

import java.util.HashMap;

import org.wso2.carbon.event.broker.CarbonEventBroker;
import org.wso2.carbon.event.broker.CarbonNotificationManager;
import org.wso2.carbon.event.broker.subscriptions.InMemorySubscriptionManager;
import org.wso2.event.Event;
import org.wso2.event.EventBrokerService;
import org.wso2.event.EventDispatcher;
import org.wso2.event.EventFilterDesc;
import org.wso2.event.Subscription;
import org.wso2.event.exceptions.EventException;

import junit.framework.TestCase;

public class NonCarbonPubSubTest extends TestCase{

  public NonCarbonPubSubTest() {
    super();
  }

  public NonCarbonPubSubTest(String name) {
    super(name);
  }
 
  public void testBasicPubSub() throws Exception{
    EventBrokerService brokerInstance = CarbonEventBroker.getInstance();
    ((CarbonEventBroker)brokerInstance).registerSubscriptionManager(new InMemorySubscriptionManager());
    CarbonNotificationManager notifyManager = new CarbonNotificationManager();
    notifyManager.init(new HashMap<String, String>());
    ((CarbonEventBroker)brokerInstance).registerNotificationManager(notifyManager);
   
    Subscription subscription = new Subscription();
    String topic = "testTopic";
    subscription.setFilterDesc(new EventFilterDesc(null, topic));
   
   
   
    EventDispatcher dispatcher = new EventDispatcher<Object>() {
      public boolean onMatchingEvent(Event<Object> event,
          Subscription subscription) throws EventException {
        System.out.println("received "+event);
        return false;
      }
    };
   
    brokerInstance.subscribeNonPersistantly(subscription, dispatcher);
   
    brokerInstance.publishEvent(new Event(new Object(), topic));
   
    Thread.sleep(10000);
  }

}
TOP

Related Classes of org.wso2.carbon.event.broker.pubsub.NonCarbonPubSubTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.