Search in sources :

Example 1 with RemoteServiceAdminEvent

use of org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent in project ecf by eclipse.

the class AbstractRemoteServiceRegisterTest method testRegisterAndUpdateProperties.

public void testRegisterAndUpdateProperties() throws Exception {
    remoteServiceAdminEvents.clear();
    // register RemoteServiceAdminListener
    ServiceRegistration listenerReg = getContext().registerService(RemoteServiceAdminListener.class.getName(), createRemoteServiceAdminListener(), null);
    // Create server container
    this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(), new Object[] { createServerID() });
    // Create props
    Properties props = getServiceProperties();
    // Put "1" for "testonekey"
    props.put("testonekey", "1");
    // Actually register with default service (IConcatService) as a remote service
    registration = registerDefaultService(props);
    ExportReference exportRef = null;
    Thread.sleep(15000);
    for (RemoteServiceAdminEvent e : remoteServiceAdminEvents) if (e.getType() == RemoteServiceAdminEvent.EXPORT_REGISTRATION)
        exportRef = e.getExportReference();
    assertTrue(exportRef != null);
    // remoteServiceAdminEvents should have the Export registration
    assertTrue(remoteServiceAdminEvents.size() > 0);
    // Get ExportReference
    EndpointDescription oldED = exportRef.getExportedEndpoint();
    assertNotNull(oldED);
    Map<String, ?> oldEDProperties = oldED.getProperties();
    assertNotNull(oldEDProperties);
    assertTrue("1".equals(oldEDProperties.get("testonekey")));
    assertTrue(oldEDProperties.get("testtwokey") == null);
    // Change testonekey value to "two" and set a new property "testtwokey" to "2"
    props.put("testonekey", "two");
    props.put("testtwokey", "2");
    // Set/update the properties on the registration
    this.registration.setProperties(props);
    // Now get new EndpointDescription and test that new properties have been changed in EndpointDescription
    EndpointDescription updatedED = exportRef.getExportedEndpoint();
    assertNotNull(updatedED);
    Map<String, ?> updatedEDProperties = updatedED.getProperties();
    assertNotNull(updatedEDProperties);
    assertTrue("two".equals(updatedEDProperties.get("testonekey")));
    assertTrue("2".equals(updatedEDProperties.get("testtwokey")));
    Thread.sleep(15000);
    listenerReg.unregister();
}
Also used : RemoteServiceAdminListener(org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener) ExportReference(org.osgi.service.remoteserviceadmin.ExportReference) EndpointDescription(org.osgi.service.remoteserviceadmin.EndpointDescription) Properties(java.util.Properties) RemoteServiceAdminEvent(org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with RemoteServiceAdminEvent

use of org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent in project ecf by eclipse.

the class TopologyManagerImpl method handleRemoteAdminEvent.

// RemoteServiceAdminListener impl
protected void handleRemoteAdminEvent(RemoteServiceAdminEvent event) {
    if (!(event instanceof RemoteServiceAdmin.RemoteServiceAdminEvent))
        return;
    RemoteServiceAdmin.RemoteServiceAdminEvent rsaEvent = (RemoteServiceAdmin.RemoteServiceAdminEvent) event;
    int eventType = event.getType();
    EndpointDescription endpointDescription = rsaEvent.getEndpointDescription();
    switch(eventType) {
        case RemoteServiceAdminEvent.EXPORT_REGISTRATION:
            advertiseEndpointDescription(endpointDescription);
            break;
        case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION:
            unadvertiseEndpointDescription(endpointDescription);
            break;
        case RemoteServiceAdminEvent.EXPORT_ERROR:
            // $NON-NLS-1$ //$NON-NLS-2$
            logError("handleRemoteAdminEvent.EXPORT_ERROR", "Export error with event=" + rsaEvent);
            break;
        case RemoteServiceAdminEvent.EXPORT_WARNING:
            // $NON-NLS-1$ //$NON-NLS-2$
            logWarning("handleRemoteAdminEvent.EXPORT_WARNING", "Export warning with event=" + rsaEvent);
            break;
        case RemoteServiceAdminEvent.EXPORT_UPDATE:
            advertiseModifyEndpointDescription(endpointDescription);
            break;
        case RemoteServiceAdminEvent.IMPORT_REGISTRATION:
            break;
        case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION:
            break;
        case RemoteServiceAdminEvent.IMPORT_ERROR:
            // $NON-NLS-1$//$NON-NLS-2$
            logError("handleRemoteAdminEvent.IMPORT_ERROR", "Import error with event=" + rsaEvent);
            break;
        case RemoteServiceAdminEvent.IMPORT_WARNING:
            // $NON-NLS-1$ //$NON-NLS-2$
            logWarning("handleRemoteAdminEvent.IMPORT_WARNING", "Import warning with event=" + rsaEvent);
            break;
        default:
            logWarning(// $NON-NLS-1$
            "handleRemoteAdminEvent", // $NON-NLS-1$ //$NON-NLS-2$
            "RemoteServiceAdminEvent=" + rsaEvent + " received with unrecognized type");
    }
}
Also used : RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) EndpointDescription(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription) RemoteServiceAdminEvent(org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent)

Aggregations

RemoteServiceAdminEvent (org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent)2 Properties (java.util.Properties)1 EndpointDescription (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)1 RemoteServiceAdmin (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 EndpointDescription (org.osgi.service.remoteserviceadmin.EndpointDescription)1 ExportReference (org.osgi.service.remoteserviceadmin.ExportReference)1 RemoteServiceAdminListener (org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener)1