Search in sources :

Example 1 with SerializationHandler

use of org.eclipse.ecf.remoteservice.eventadmin.serialization.SerializationHandler in project ecf by eclipse.

the class DistributedEventAdmin method start.

/**
 * Start this distributed event admin instance. This method should be called
 * prior to registering this object as an {@link EventAdmin} implementation
 * with the OSGi service registry.
 */
public void start() {
    if (logTracker != null)
        logTracker.open();
    // $NON-NLS-1$
    ThreadGroup eventGroup = new ThreadGroup("Distributed EventAdmin");
    eventGroup.setDaemon(true);
    eventManager = new EventManager("Distributed EventAdmin Async Event Dispatcher Thread", eventGroup);
    eventHandlerTracker.open();
    // Other services can contribute Event topic filters which will be ignored
    // by the distribution part of DistributedEventAdmin. This is primarily useful
    // in cases where the Event data cannot be serialized or serialization is too
    // expensive.
    etfServiceTracker = new ServiceTracker(this.context, EventTopicFilter.class, new ServiceTrackerCustomizer() {

        public Object addingService(ServiceReference reference) {
            final EventTopicFilter etf = (EventTopicFilter) context.getService(reference);
            addEventTopicFilters(etf.getFilters());
            return etf;
        }

        public void modifiedService(ServiceReference reference, Object service) {
        // nop
        }

        public void removedService(ServiceReference reference, Object service) {
            final EventTopicFilter etf = (EventTopicFilter) service;
            removeEventTopicFilters(etf.getFilters());
        }
    });
    etfServiceTracker.open();
    // SerializationHandler are responsible to handle serialization of Event properties
    shServiceTracker = new ServiceTracker(this.context, SerializationHandler.class, new ServiceTrackerCustomizer() {

        public Object addingService(ServiceReference reference) {
            final SerializationHandler sh = (SerializationHandler) context.getService(reference);
            topic2serializationHandler.put(sh.getTopic(), sh);
            return sh;
        }

        public void modifiedService(ServiceReference reference, Object service) {
        // nop
        }

        public void removedService(ServiceReference reference, Object service) {
            final SerializationHandler sh = (SerializationHandler) service;
            topic2serializationHandler.remove(sh.getTopic());
        }
    });
    shServiceTracker.open();
}
Also used : EventManager(org.eclipse.osgi.framework.eventmgr.EventManager) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) DefaultSerializationHandler(org.eclipse.ecf.internal.remoteservice.eventadmin.DefaultSerializationHandler) SerializationHandler(org.eclipse.ecf.remoteservice.eventadmin.serialization.SerializationHandler) BaseSharedObject(org.eclipse.ecf.core.sharedobject.BaseSharedObject) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

BaseSharedObject (org.eclipse.ecf.core.sharedobject.BaseSharedObject)1 DefaultSerializationHandler (org.eclipse.ecf.internal.remoteservice.eventadmin.DefaultSerializationHandler)1 SerializationHandler (org.eclipse.ecf.remoteservice.eventadmin.serialization.SerializationHandler)1 EventManager (org.eclipse.osgi.framework.eventmgr.EventManager)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1