From 46cf063609de706aff74dc6d204f4e45df0240ea Mon Sep 17 00:00:00 2001 From: slewis Date: Thu, 9 Apr 2015 16:32:43 -0700 Subject: Simplified timeservice host and consumer by using DebugRemoteServiceAdminListener utility class for debug output Change-Id: I81e8a0ad0c97cb936532b25722173a192ec285af --- .../examples/timeservice/host/Activator.java | 39 ++-------------------- .../examples/timeservice/host/ActivatorSimple.java | 38 --------------------- 2 files changed, 3 insertions(+), 74 deletions(-) delete mode 100644 examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/ActivatorSimple.java (limited to 'examples/bundles/com.mycorp.examples.timeservice.host/src') diff --git a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java index 997d05723..3e1aa4f82 100644 --- a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java +++ b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java @@ -12,10 +12,10 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.Properties; +import org.eclipse.ecf.osgi.services.remoteserviceadmin.DebugRemoteServiceAdminListener; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent; import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener; import com.mycorp.examples.timeservice.ITimeService; @@ -26,7 +26,8 @@ public class Activator implements BundleActivator { // If the verboseRemoteServiceAdmin system property is set // then register debug listener if (Boolean.getBoolean("verboseRemoteServiceAdmin")) - registerDebugListener(context); + context.registerService(RemoteServiceAdminListener.class, + new DebugRemoteServiceAdminListener(), null); // Create remote service properties...see // createRemoteServiceProperties() @@ -67,38 +68,4 @@ public class Activator implements BundleActivator { return result; } - // Register a RemoteServiceAdminListener so we can report to sdtout - // when a remote service has actually been successfully exported by - // the RSA implementation - private void registerDebugListener(BundleContext context) { - RemoteServiceAdminListener rsaListener = new RemoteServiceAdminListener() { - public void remoteAdminEvent(RemoteServiceAdminEvent event) { - switch (event.getType()) { - case RemoteServiceAdminEvent.EXPORT_REGISTRATION: - System.out - .println("RSA: Service Exported. EndpointDescription=" - + event.getExportReference() - .getExportedEndpoint() - .getProperties()); - break; - case RemoteServiceAdminEvent.EXPORT_ERROR: - Throwable t = event.getException(); - System.err.println("RSA: EXPORT ERROR. Error message=" - + ((t == null) ? "none" : t.getMessage()) - + ". EndpointDescription=" - + event.getExportReference().getExportedEndpoint() - .getProperties() + ""); - if (t != null) - t.printStackTrace(); - break; - } - } - - }; - // Register our listener as service via whiteboard pattern, and - // RemoteServiceAdmin will callback - context.registerService(RemoteServiceAdminListener.class.getName(), - rsaListener, null); - } - } diff --git a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/ActivatorSimple.java b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/ActivatorSimple.java deleted file mode 100644 index 4406486df..000000000 --- a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/ActivatorSimple.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Composent, Inc. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: Scott Lewis - initial API and implementation - ******************************************************************************/ -package com.mycorp.examples.timeservice.host; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -import com.mycorp.examples.timeservice.ITimeService; - -public class ActivatorSimple implements BundleActivator { - - public void start(BundleContext context) throws Exception { - Dictionary props = new Hashtable(); - props.put("service.exported.interfaces", "*"); - props.put("service.exported.configs","ecf.generic.server"); - props.put("ecf.generic.server.id", "ecftcp://localhost:3288/server"); - ServiceRegistration timeServiceRegistration = context - .registerService(ITimeService.class, new TimeServiceImpl(), - props); - System.out.println("MyTimeService host registered with registration=" - + timeServiceRegistration); - } - - public void stop(BundleContext context) throws Exception { - // do nothing - } - -} -- cgit v1.2.3