/* Copyright 2009 Ramon Servadei Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package fulmine.demo; import java.io.IOException; import fulmine.Domain; import fulmine.Type; import fulmine.context.FulmineContext; import fulmine.context.IFulmineContext; import fulmine.distribution.connection.tcp.TcpNetwork; import fulmine.event.IEvent; import fulmine.event.IEventSource; import fulmine.event.listener.EventListenerUtils; import fulmine.event.subscription.ISubscription; import fulmine.event.subscription.ISubscriptionListener; import fulmine.model.container.IContainer; public class HelloWorld { public static void main(String[] args) { IFulmineContext publisherContext = new FulmineContext("HelloWorldPublisher"); publisherContext.setNetwork(new TcpNetwork()); publisherContext.start(); IFulmineContext subscriberContext = new FulmineContext("HelloWorldSubscriber"); subscriberContext.setNetwork(new TcpNetwork(null, 22222)); subscriberContext.start(); subscriberContext.subscribe("HelloWorldPublisher", "helloWorld", ISubscription.WILDCARD_TYPE, ISubscription.WILDCARD_DOMAIN, new ISubscriptionListener() { private final Class[] FILTER = EventListenerUtils.createFilter(IContainer.class); public void addedAsListenerFor(IEventSource source) { // noop } public void removedAsListenerFrom(IEventSource source) { // noop } public Class[] getEventTypeFilter() { // this method is called whenever an event is to be // distributed so we should not be re-creating the array // each time return FILTER; } public void update(IEvent event) { System.out.println("received " + event); } }); // this creates the record publisherContext.getLocalContainer("helloWorld", Type.RECORD, Domain.get(1, "Tutorial")); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } } }