Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[PAXSB-65] applied formatter, added license headers

  • Loading branch information...
commit ba6ab790b7d1f1bb0f95bc92f41dce25d5d58bdd 1 parent 6902262
@hwellmann hwellmann authored
View
154 pax-swissbox-framework/src/main/java/org/ops4j/pax/swissbox/framework/RemoteFramework.java
@@ -28,14 +28,14 @@
/**
* An RMI-capable variant of the OSGi {@link Framework} interface.
-
+ *
* @author Harald Wellmann
*/
public interface RemoteFramework extends Remote
{
public static final String RMI_PORT_KEY = "pax.swissbox.framework.rmi.port";
public static final String RMI_NAME_KEY = "pax.swissbox.framework.rmi.name";
-
+
/**
* Initializes the framework.
*
@@ -62,120 +62,125 @@
* @throws BundleException
*/
void stop() throws RemoteException, BundleException;
-
+
/**
* Installs a bundle remotely.
- *
- * @param bundleUrl url of the bundle to be installed. The url must be accessible from the remote framework.
+ *
+ * @param bundleUrl url of the bundle to be installed. The url must be accessible from the
+ * remote framework.
* @return bundle id of the installed bundle
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from installing the bundle
*/
- long installBundle(String bundleUrl)
- throws RemoteException, BundleException;
+ long installBundle( String bundleUrl )
+ throws RemoteException, BundleException;
-
/**
* Installs a bundle remotely, sets its start level and optionally starts it.
- *
- * @param bundleUrl url of the bundle to be installed. The url must be accessible from the remote framework.
+ *
+ * @param bundleUrl url of the bundle to be installed. The url must be accessible from the
+ * remote framework.
* @param start indicates whether the bundle will be started
* @param startLevel start level for this bundle
* @return bundle id of the installed bundle
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from installing the bundle
*/
- long installBundle(String bundleUrl, boolean start, int startLevel)
- throws RemoteException, BundleException;
-
+ long installBundle( String bundleUrl, boolean start, int startLevel )
+ throws RemoteException, BundleException;
+
/**
- * Installs a bundle remotely, given the bundle content, autostart it if requested and set its startlevel
- *
+ * Installs a bundle remotely, given the bundle content, autostart it if requested and set its
+ * startlevel
+ *
* @param bundleLocation The location identifier of the bundle to install
- * @param bundleData bundle content as a byte array
+ * @param bundleData bundle content as a byte array
* @param start indicates whether the bundle will be started
* @param startLevel start level for this bundle
* @return bundle id of the installed bundle
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from installing the bundle
*/
- long installBundle(String bundleLocation, byte[] bundleData, boolean start, int startLevel)
- throws RemoteException, BundleException;
-
+ long installBundle( String bundleLocation, byte[] bundleData, boolean start, int startLevel )
+ throws RemoteException, BundleException;
+
/**
* Installs a bundle remotely, given the bundle content.
- *
+ *
* @param bundleLocation The location identifier of the bundle to install
- * @param bundle bundle content as a byte array
+ * @param bundle bundle content as a byte array
* @return bundle id of the installed bundle
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from installing the bundle
*/
- long installBundle(String bundleLocation, byte[] bundle)
- throws RemoteException, BundleException;
+ long installBundle( String bundleLocation, byte[] bundle )
+ throws RemoteException, BundleException;
/**
* Starts a bundle.
- *
+ *
* @param bundleId id of the bundle to be started
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from starting the bundle
*/
- void startBundle(long bundleId)
- throws RemoteException, BundleException;
+ void startBundle( long bundleId )
+ throws RemoteException, BundleException;
/**
* Stops a bundle.
- *
+ *
* @param bundleId id of the bundle to be stopped
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - Re-thrown from stopping the bundle
*/
- void stopBundle(long bundleId)
- throws RemoteException, BundleException;
+ void stopBundle( long bundleId )
+ throws RemoteException, BundleException;
/**
* Sets bundle start level.
- *
- * @param bundleId id of the bundle to which the start level should be set
+ *
+ * @param bundleId id of the bundle to which the start level should be set
* @param startLevel bundle start level
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - If bundle level cannot be set
*/
- void setBundleStartLevel(long bundleId, int startLevel)
- throws RemoteException, BundleException;
+ void setBundleStartLevel( long bundleId, int startLevel )
+ throws RemoteException, BundleException;
/**
* Waits for a bundle to be in a certain state and returns.
- *
- * @param bundleId bundle id
- * @param state expected state
+ *
+ * @param bundleId bundle id
+ * @param state expected state
* @param timeoutInMillis max time to wait for state
- * @throws RemoteException - Remote communication related exception (mandatory by RMI)
- * @throws BundleException - If bundle cannot be found
- * @throws org.ops4j.pax.exam.TimeoutException - if timeout occured and expected state has not being reached
+ * @throws RemoteException - Remote communication related exception (mandatory by RMI)
+ * @throws BundleException - If bundle cannot be found
+ * @throws org.ops4j.pax.exam.TimeoutException - if timeout occured and expected state has not
+ * being reached
*/
- void waitForState(long bundleId, int state, long timeoutInMillis)
- throws RemoteException, BundleException;
+ void waitForState( long bundleId, int state, long timeoutInMillis )
+ throws RemoteException, BundleException;
/**
* @param id of bundle to uninstall
* @throws RemoteException - Remote communication related exception (mandatory by RMI)
* @throws BundleException - If bundle cannot be found
*/
- void uninstallBundle(long id)
- throws RemoteException, BundleException;
+ void uninstallBundle( long id )
+ throws RemoteException, BundleException;
+
/**
* Looks up a service matching the given filter and invokes a service method with the given
- * name. The method is expected to have either a parameter of type Object[] or no parameters.
- * It will be invoked with an empty argument list.
- * @param filter LDAP service filter
+ * name. The method is expected to have either a parameter of type Object[] or no parameters. It
+ * will be invoked with an empty argument list.
+ *
+ * @param filter LDAP service filter
* @param methodName service method name
- * @throws RemoteException - Remote communication related exception (mandatory by RMI)
- * @throws BundleException - If bundle cannot be found
+ * @throws RemoteException - Remote communication related exception (mandatory by RMI)
+ * @throws BundleException - If bundle cannot be found
*/
- void callService(String filter, String methodName) throws RemoteException, BundleException;
-
+ void callService( String filter, String methodName ) throws RemoteException, BundleException;
+
/**
* Invokes a method on this reference in the remote framework
*
@@ -183,8 +188,9 @@ void uninstallBundle(long id)
* @param args
* @return
*/
- Object invokeMethodOnService(RemoteServiceReference reference, String methodName, Object... args) throws RemoteException, Exception;
-
+ Object invokeMethodOnService( RemoteServiceReference reference, String methodName,
+ Object... args ) throws RemoteException, Exception;
+
/**
* Invokes a method on this reference in the remote framework
*
@@ -192,56 +198,66 @@ void uninstallBundle(long id)
* @param args
* @return
*/
- Object invokeMethodOnService(RemoteServiceReference reference, String methodName, Class<?>[] parameterTypes, Object[] args) throws RemoteException, Exception;
-
+ Object invokeMethodOnService( RemoteServiceReference reference, String methodName,
+ Class<?>[] parameterTypes, Object[] args ) throws RemoteException, Exception;
+
/**
- * Fetch an array of {@link RemoteServiceReference} to interact with them, this is a snapshot of the current state and must be recalled to update
+ * Fetch an array of {@link RemoteServiceReference} to interact with them, this is a snapshot of
+ * the current state and must be recalled to update
+ *
* @param filter
* @return
* @throws RemoteException
* @throws BundleException
* @throws InvalidSyntaxException
*/
- RemoteServiceReference[] getServiceReferences(String filter) throws RemoteException, BundleException, InvalidSyntaxException;
-
+ RemoteServiceReference[] getServiceReferences( String filter ) throws RemoteException,
+ BundleException, InvalidSyntaxException;
+
/**
- * Fetch an array of {@link RemoteServiceReference} to interact with them, this is a snapshot of the current state and must be recalled to update
+ * Fetch an array of {@link RemoteServiceReference} to interact with them, this is a snapshot of
+ * the current state and must be recalled to update
+ *
* @param filter
- * @param timeout wait the specified amout of time in relation to the timeunit for a service matchign the filter to appear
+ * @param timeout wait the specified amout of time in relation to the timeunit for a service
+ * matchign the filter to appear
* @return
* @throws RemoteException
* @throws BundleException
* @throws InvalidSyntaxException
*/
- RemoteServiceReference[] getServiceReferences(String filter, long timeout, TimeUnit timeUnit) throws RemoteException, BundleException, InvalidSyntaxException;
-
-
+ RemoteServiceReference[] getServiceReferences( String filter, long timeout, TimeUnit timeUnit )
+ throws RemoteException, BundleException, InvalidSyntaxException;
+
/**
* Sets the framework startlevel.
+ *
* @see {@link StartLevel#setStartLevel(int)}
* @param startLevel
* @throws RemoteException
*/
- void setFrameworkStartLevel(int startLevel) throws RemoteException;
-
+ void setFrameworkStartLevel( int startLevel ) throws RemoteException;
+
/**
* Sets the framework startlevel and waits for at most the given timeout (in ms) for the
- * startlevel to be reached.
+ * startlevel to be reached.
+ *
* @see {@link StartLevel#setStartLevel(int)}
* @param startLevel
* @throws RemoteException
* @return true if the start level has been reached within the given timeout
*/
- boolean setFrameworkStartLevel(int startLevel, long timeout)
- throws RemoteException;
-
+ boolean setFrameworkStartLevel( int startLevel, long timeout )
+ throws RemoteException;
+
/**
* Returns the state of the bundle with the given ID.
+ *
* @see {@link org.osgi.framework.Bundle#getState()}
* @param bundleId bundle ID
* @return state of bundle
* @throws RemoteException
* @throws BundleException if there is no bundle with the given ID
*/
- int getBundleState(long bundleId) throws RemoteException, BundleException;
+ int getBundleState( long bundleId ) throws RemoteException, BundleException;
}
View
411 ...wissbox-framework/src/main/java/org/ops4j/pax/swissbox/framework/RemoteFrameworkImpl.java
@@ -51,285 +51,386 @@
import org.osgi.util.tracker.ServiceTracker;
/**
- * Implements the {@link RemoteFramework} interface by instantiating a local
- * {@link Framework}, exporting it via an RMI registry and delegating all remote
- * calls to the local framework.
+ * Implements the {@link RemoteFramework} interface by instantiating a local {@link Framework},
+ * exporting it via an RMI registry and delegating all remote calls to the local framework.
*
* @author Harald Wellmann
*/
-public class RemoteFrameworkImpl implements RemoteFramework {
+public class RemoteFrameworkImpl implements RemoteFramework
+{
- private static Logger LOG = Logger.getLogger(RemoteFrameworkImpl.class.getName());
+ private static Logger LOG = Logger.getLogger( RemoteFrameworkImpl.class.getName() );
- private Framework framework;
- private Registry registry;
- private String name;
+ private Framework framework;
+ private Registry registry;
+ private String name;
- public RemoteFrameworkImpl(Map<String, String> frameworkProperties) throws RemoteException, AlreadyBoundException, BundleException {
+ public RemoteFrameworkImpl( Map<String, String> frameworkProperties ) throws RemoteException,
+ AlreadyBoundException, BundleException
+ {
FrameworkFactory frameworkFactory = findFrameworkFactory();
- this.framework = frameworkFactory.newFramework(frameworkProperties);
+ this.framework = frameworkFactory.newFramework( frameworkProperties );
export();
}
- private void export() throws RemoteException, AccessException {
- String port = System.getProperty(RMI_PORT_KEY, "1099");
- name = System.getProperty(RMI_NAME_KEY);
- registry = LocateRegistry.getRegistry(Integer.parseInt(port));
+ private void export() throws RemoteException, AccessException
+ {
+ String port = System.getProperty( RMI_PORT_KEY, "1099" );
+ name = System.getProperty( RMI_NAME_KEY );
+ registry = LocateRegistry.getRegistry( Integer.parseInt( port ) );
URL location1 = getClass().getProtectionDomain().getCodeSource().getLocation();
URL location2 = Bundle.class.getProtectionDomain().getCodeSource().getLocation();
URL location3 = ServiceLookup.class.getProtectionDomain().getCodeSource().getLocation();
- System.setProperty("java.rmi.server.codebase", location1 + " " + location2 + " " + location3);
- Remote remote = UnicastRemoteObject.exportObject(this, 0);
- registry.rebind(name, remote);
+ System.setProperty( "java.rmi.server.codebase", location1 + " " + location2 + " "
+ + location3 );
+ Remote remote = UnicastRemoteObject.exportObject( this, 0 );
+ registry.rebind( name, remote );
}
- public void init() throws RemoteException, BundleException {
+ public void init() throws RemoteException, BundleException
+ {
framework.init();
}
- public void start() throws RemoteException, BundleException {
+ public void start() throws RemoteException, BundleException
+ {
framework.start();
}
- public void stop() throws RemoteException, BundleException {
+ public void stop() throws RemoteException, BundleException
+ {
framework.stop();
- try {
- registry.unbind(name);
- } catch (NotBoundException exc) {
- throw new IllegalStateException(exc);
+ try
+ {
+ registry.unbind( name );
}
- UnicastRemoteObject.unexportObject(this, true);
+ catch ( NotBoundException exc )
+ {
+ throw new IllegalStateException( exc );
+ }
+ UnicastRemoteObject.unexportObject( this, true );
}
- public long installBundle(String bundleUrl) throws RemoteException, BundleException {
- Bundle bundle = framework.getBundleContext().installBundle(bundleUrl);
+ public long installBundle( String bundleUrl ) throws RemoteException, BundleException
+ {
+ Bundle bundle = framework.getBundleContext().installBundle( bundleUrl );
return bundle.getBundleId();
}
- public long installBundle(String bundleUrl, boolean start, int startLevel) throws RemoteException, BundleException {
+ public long installBundle( String bundleUrl, boolean start, int startLevel )
+ throws RemoteException, BundleException
+ {
BundleContext bundleContext = framework.getBundleContext();
- Bundle bundle = bundleContext.installBundle(bundleUrl);
- setupBundle(start, startLevel, bundleContext, bundle);
+ Bundle bundle = bundleContext.installBundle( bundleUrl );
+ setupBundle( start, startLevel, bundleContext, bundle );
return bundle.getBundleId();
}
- public long installBundle(String bundleLocation, byte[] bundleData, boolean start, int startLevel) throws RemoteException, BundleException {
+ public long installBundle( String bundleLocation, byte[] bundleData, boolean start,
+ int startLevel ) throws RemoteException, BundleException
+ {
BundleContext bundleContext = framework.getBundleContext();
- Bundle bundle = bundleContext.installBundle(bundleLocation, new ByteArrayInputStream(bundleData));
- setupBundle(start, startLevel, bundleContext, bundle);
+ Bundle bundle =
+ bundleContext.installBundle( bundleLocation, new ByteArrayInputStream( bundleData ) );
+ setupBundle( start, startLevel, bundleContext, bundle );
return bundle.getBundleId();
}
- private static void setupBundle(boolean start, int startLevel, BundleContext bundleContext, Bundle bundle) throws BundleException {
- StartLevel sl = ServiceLookup.getService(bundleContext, StartLevel.class);
- sl.setBundleStartLevel(bundle, startLevel);
+ private static void setupBundle( boolean start, int startLevel, BundleContext bundleContext,
+ Bundle bundle ) throws BundleException
+ {
+ StartLevel sl = ServiceLookup.getService( bundleContext, StartLevel.class );
+ sl.setBundleStartLevel( bundle, startLevel );
- if (start) {
+ if( start )
+ {
bundle.start();
}
}
- public long installBundle(String bundleLocation, byte[] bundleData) throws RemoteException, BundleException {
- Bundle bundle = framework.getBundleContext().installBundle(bundleLocation, new ByteArrayInputStream(bundleData));
+ public long installBundle( String bundleLocation, byte[] bundleData ) throws RemoteException,
+ BundleException
+ {
+ Bundle bundle =
+ framework.getBundleContext().installBundle( bundleLocation,
+ new ByteArrayInputStream( bundleData ) );
return bundle.getBundleId();
}
- public void startBundle(long bundleId) throws RemoteException, BundleException {
- framework.getBundleContext().getBundle(bundleId).start();
+ public void startBundle( long bundleId ) throws RemoteException, BundleException
+ {
+ framework.getBundleContext().getBundle( bundleId ).start();
}
- public void stopBundle(long bundleId) throws RemoteException, BundleException {
- framework.getBundleContext().getBundle(bundleId).stop();
+ public void stopBundle( long bundleId ) throws RemoteException, BundleException
+ {
+ framework.getBundleContext().getBundle( bundleId ).stop();
}
- public void setBundleStartLevel(long bundleId, int startLevel) throws RemoteException, BundleException {
+ public void setBundleStartLevel( long bundleId, int startLevel ) throws RemoteException,
+ BundleException
+ {
BundleContext bc = framework.getBundleContext();
- StartLevel sl = ServiceLookup.getService(bc, StartLevel.class);
- Bundle bundle = bc.getBundle(bundleId);
- sl.setBundleStartLevel(bundle, startLevel);
+ StartLevel sl = ServiceLookup.getService( bc, StartLevel.class );
+ Bundle bundle = bc.getBundle( bundleId );
+ sl.setBundleStartLevel( bundle, startLevel );
}
- public void uninstallBundle(long id) throws RemoteException, BundleException {
- framework.getBundleContext().getBundle(id).uninstall();
+ public void uninstallBundle( long id ) throws RemoteException, BundleException
+ {
+ framework.getBundleContext().getBundle( id ).uninstall();
}
- public FrameworkFactory findFrameworkFactory() {
- ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class);
+ public FrameworkFactory findFrameworkFactory()
+ {
+ ServiceLoader<FrameworkFactory> loader = ServiceLoader.load( FrameworkFactory.class );
FrameworkFactory factory = loader.iterator().next();
return factory;
}
- private static Map<String, String> buildFrameworkProperties(String[] args) {
+ private static Map<String, String> buildFrameworkProperties( String[] args )
+ {
Map<String, String> props = new HashMap<String, String>();
- for (String arg : args) {
- if (arg.startsWith("-F")) {
- int eq = arg.indexOf("=");
- if (eq == -1) {
- String key = arg.substring(2);
- props.put(key, null);
- } else {
- String key = arg.substring(2, eq);
- String value = arg.substring(eq + 1);
- props.put(key, value);
+ for( String arg : args )
+ {
+ if( arg.startsWith( "-F" ) )
+ {
+ int eq = arg.indexOf( "=" );
+ if( eq == -1 )
+ {
+ String key = arg.substring( 2 );
+ props.put( key, null );
+ }
+ else
+ {
+ String key = arg.substring( 2, eq );
+ String value = arg.substring( eq + 1 );
+ props.put( key, value );
}
- } else {
- LOG.warning("ignoring unknown argument " + arg);
+ }
+ else
+ {
+ LOG.warning( "ignoring unknown argument " + arg );
}
}
return props;
}
- public void callService(String filter, String methodName) throws RemoteException, BundleException {
- try {
- LOG.fine("acquiring service " + filter);
+ public void callService( String filter, String methodName ) throws RemoteException,
+ BundleException
+ {
+ try
+ {
+ LOG.fine( "acquiring service " + filter );
BundleContext bc = framework.getBundleContext();
- Object service = ServiceLookup.getServiceByFilter(bc, filter);
+ Object service = ServiceLookup.getServiceByFilter( bc, filter );
Class<? extends Object> klass = service.getClass();
Method method;
- try {
- method = klass.getMethod(methodName, Object[].class);
- LOG.fine("calling service method " + method);
- method.invoke(service, (Object) new Object[] {});
- } catch (NoSuchMethodException e) {
- method = klass.getMethod(methodName);
- LOG.fine("calling service method " + method);
- method.invoke(service);
+ try
+ {
+ method = klass.getMethod( methodName, Object[].class );
+ LOG.fine( "calling service method " + method );
+ method.invoke( service, (Object) new Object[]{} );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ method = klass.getMethod( methodName );
+ LOG.fine( "calling service method " + method );
+ method.invoke( service );
}
- } catch (SecurityException exc) {
- throw new IllegalStateException(exc);
- } catch (NoSuchMethodException exc) {
- throw new IllegalStateException(exc);
- } catch (IllegalArgumentException exc) {
- throw new IllegalStateException(exc);
- } catch (IllegalAccessException exc) {
- throw new IllegalStateException(exc);
- } catch (InvocationTargetException exc) {
- throw new IllegalStateException(exc);
+ }
+ catch ( SecurityException exc )
+ {
+ throw new IllegalStateException( exc );
+ }
+ catch ( NoSuchMethodException exc )
+ {
+ throw new IllegalStateException( exc );
+ }
+ catch ( IllegalArgumentException exc )
+ {
+ throw new IllegalStateException( exc );
+ }
+ catch ( IllegalAccessException exc )
+ {
+ throw new IllegalStateException( exc );
+ }
+ catch ( InvocationTargetException exc )
+ {
+ throw new IllegalStateException( exc );
}
}
- public void setFrameworkStartLevel(int startLevel) throws RemoteException {
- setFrameworkStartLevel(startLevel, 0);
+ public void setFrameworkStartLevel( int startLevel ) throws RemoteException
+ {
+ setFrameworkStartLevel( startLevel, 0 );
}
- public boolean setFrameworkStartLevel(final int startLevel, long timeout) throws RemoteException {
+ public boolean setFrameworkStartLevel( final int startLevel, long timeout )
+ throws RemoteException
+ {
BundleContext bc = framework.getBundleContext();
- final StartLevel sl = ServiceLookup.getService(bc, StartLevel.class);
- final CountDownLatch latch = new CountDownLatch(1);
- bc.addFrameworkListener(new FrameworkListener() {
-
- public void frameworkEvent(FrameworkEvent frameworkEvent) {
- switch (frameworkEvent.getType()) {
+ final StartLevel sl = ServiceLookup.getService( bc, StartLevel.class );
+ final CountDownLatch latch = new CountDownLatch( 1 );
+ bc.addFrameworkListener( new FrameworkListener()
+ {
+
+ public void frameworkEvent( FrameworkEvent frameworkEvent )
+ {
+ switch( frameworkEvent.getType() )
+ {
case FrameworkEvent.STARTLEVEL_CHANGED:
- if (sl.getStartLevel() == startLevel) {
+ if( sl.getStartLevel() == startLevel )
+ {
latch.countDown();
}
}
}
- });
- sl.setStartLevel(startLevel);
+ } );
+ sl.setStartLevel( startLevel );
boolean startLevelReached;
- try {
- startLevelReached = latch.await(timeout, TimeUnit.MILLISECONDS);
+ try
+ {
+ startLevelReached = latch.await( timeout, TimeUnit.MILLISECONDS );
return startLevelReached;
- } catch (InterruptedException exc) {
- throw new RemoteException("interrupted while waiting", exc);
+ }
+ catch ( InterruptedException exc )
+ {
+ throw new RemoteException( "interrupted while waiting", exc );
}
}
- public void waitForState(long bundleId, int state, long timeoutInMillis) throws RemoteException, BundleException {
- throw new UnsupportedOperationException("not yet implemented");
+ public void waitForState( long bundleId, int state, long timeoutInMillis )
+ throws RemoteException, BundleException
+ {
+ throw new UnsupportedOperationException( "not yet implemented" );
}
- public int getBundleState(long bundleId) throws RemoteException, BundleException {
- Bundle bundle = framework.getBundleContext().getBundle(bundleId);
- if (bundle == null) {
- throw new BundleException(String.format("bundle [%d] does not exist", bundleId));
+ public int getBundleState( long bundleId ) throws RemoteException, BundleException
+ {
+ Bundle bundle = framework.getBundleContext().getBundle( bundleId );
+ if( bundle == null )
+ {
+ throw new BundleException( String.format( "bundle [%d] does not exist", bundleId ) );
}
return bundle.getState();
}
- public RemoteServiceReference[] getServiceReferences(String filter) throws RemoteException, BundleException, InvalidSyntaxException {
- return getServiceReferences(filter, -1, null);
+ public RemoteServiceReference[] getServiceReferences( String filter ) throws RemoteException,
+ BundleException, InvalidSyntaxException
+ {
+ return getServiceReferences( filter, -1, null );
}
- public RemoteServiceReference[] getServiceReferences(String filter, long timeout, TimeUnit timeUnit) throws RemoteException, BundleException,
- InvalidSyntaxException {
+ public RemoteServiceReference[] getServiceReferences( String filter, long timeout,
+ TimeUnit timeUnit ) throws RemoteException, BundleException,
+ InvalidSyntaxException
+ {
BundleContext bundleContext = framework.getBundleContext();
- ServiceReference[] serviceReferences = bundleContext.getAllServiceReferences(null, filter);
- if (serviceReferences == null) {
- if (timeout < 0) {
+ ServiceReference[] serviceReferences = bundleContext.getAllServiceReferences( null, filter );
+ if( serviceReferences == null )
+ {
+ if( timeout < 0 )
+ {
return new RemoteServiceReference[0];
}
- ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter), null);
- tracker.open(true);
- try {
- tracker.waitForService(timeUnit.toMillis(timeout));
+ ServiceTracker tracker =
+ new ServiceTracker( bundleContext, bundleContext.createFilter( filter ), null );
+ tracker.open( true );
+ try
+ {
+ tracker.waitForService( timeUnit.toMillis( timeout ) );
serviceReferences = tracker.getServiceReferences();
- if (serviceReferences == null) {
- throw new IllegalStateException("services vanished too fast...");
+ if( serviceReferences == null )
+ {
+ throw new IllegalStateException( "services vanished too fast..." );
}
- } catch (InterruptedException e) {
- throw new RuntimeException("interrupted!", e);
- } finally {
+ }
+ catch ( InterruptedException e )
+ {
+ throw new RuntimeException( "interrupted!", e );
+ }
+ finally
+ {
tracker.close();
}
}
RemoteServiceReference[] remoteRefs = new RemoteServiceReference[serviceReferences.length];
- for (int i = 0; i < remoteRefs.length; i++) {
+ for( int i = 0; i < remoteRefs.length; i++ )
+ {
ServiceReference reference = serviceReferences[i];
- final String serviceFilter = "(&(" + Constants.SERVICE_ID + "=" + reference.getProperty(Constants.SERVICE_ID) + ")" + filter + ")";
+ final String serviceFilter =
+ "(&(" + Constants.SERVICE_ID + "=" + reference.getProperty( Constants.SERVICE_ID )
+ + ")" + filter + ")";
final String[] keys = reference.getPropertyKeys();
final Map<String, Object> values = new HashMap<String, Object>();
- for (String key : keys) {
- values.put(key, reference.getProperty(key));
+ for( String key : keys )
+ {
+ values.put( key, reference.getProperty( key ) );
}
- remoteRefs[i] = new RemoteServiceReferenceImplementation(values, serviceFilter);
+ remoteRefs[i] = new RemoteServiceReferenceImplementation( values, serviceFilter );
}
return remoteRefs;
}
- public Object invokeMethodOnService(RemoteServiceReference reference, String methodName, Object... args) throws RemoteException, Exception {
+ public Object invokeMethodOnService( RemoteServiceReference reference, String methodName,
+ Object... args ) throws RemoteException, Exception
+ {
Class<?>[] argTypes = new Class<?>[args.length];
- for (int i = 0; i < argTypes.length; i++) {
+ for( int i = 0; i < argTypes.length; i++ )
+ {
Object object = args[i];
- if (object == null) {
- throw new IllegalArgumentException("argument "
- + i
- + " is null, use invokeMethodOnService(RemoteServiceReference, String, Class[], Object[]) if you want to call a service with null argument values");
+ if( object == null )
+ {
+ throw new IllegalArgumentException(
+ "argument "
+ + i
+ + " is null, use invokeMethodOnService(RemoteServiceReference, String, Class[], Object[]) if you want to call a service with null argument values" );
}
argTypes[i] = object.getClass();
}
- return invokeMethodOnService(reference, methodName, argTypes, args);
+ return invokeMethodOnService( reference, methodName, argTypes, args );
}
- public Object invokeMethodOnService(RemoteServiceReference reference, String methodName, Class<?>[] parameterTypes, Object[] args) throws RemoteException,
- Exception {
+ public Object invokeMethodOnService( RemoteServiceReference reference, String methodName,
+ Class<?>[] parameterTypes, Object[] args ) throws RemoteException,
+ Exception
+ {
BundleContext bundleContext = framework.getBundleContext();
- ServiceReference[] allServiceReferences = bundleContext.getAllServiceReferences(null, reference.getServiceFilter());
- if (allServiceReferences == null || allServiceReferences.length == 0) {
- throw new IllegalStateException("service is no longer present");
+ ServiceReference[] allServiceReferences =
+ bundleContext.getAllServiceReferences( null, reference.getServiceFilter() );
+ if( allServiceReferences == null || allServiceReferences.length == 0 )
+ {
+ throw new IllegalStateException( "service is no longer present" );
+ }
+ if( allServiceReferences.length > 1 )
+ {
+ throw new AssertionError(
+ "more than one service is matching the reference, this should never happen" );
}
- if (allServiceReferences.length > 1) {
- throw new AssertionError("more than one service is matching the reference, this should never happen");
+ Object service = bundleContext.getService( allServiceReferences[0] );
+ if( service == null )
+ {
+ throw new IllegalStateException( "service has vanished between calls" );
}
- Object service = bundleContext.getService(allServiceReferences[0]);
- if (service == null) {
- throw new IllegalStateException("service has vanished between calls");
+ try
+ {
+ Method method = service.getClass().getMethod( methodName, parameterTypes );
+ return method.invoke( service, args );
}
- try {
- Method method = service.getClass().getMethod(methodName, parameterTypes);
- return method.invoke(service, args);
- } finally {
- bundleContext.ungetService(allServiceReferences[0]);
+ finally
+ {
+ bundleContext.ungetService( allServiceReferences[0] );
}
}
- public static void main(String[] args) throws RemoteException, AlreadyBoundException, BundleException, InterruptedException {
- LOG.fine("starting RemoteFrameworkImpl");
- Map<String, String> props = buildFrameworkProperties(args);
- RemoteFrameworkImpl impl = new RemoteFrameworkImpl(props);
+ public static void main( String[] args ) throws RemoteException, AlreadyBoundException,
+ BundleException, InterruptedException
+ {
+ LOG.fine( "starting RemoteFrameworkImpl" );
+ Map<String, String> props = buildFrameworkProperties( args );
+ RemoteFrameworkImpl impl = new RemoteFrameworkImpl( props );
impl.start();
}
}
View
26 ...sbox-framework/src/main/java/org/ops4j/pax/swissbox/framework/RemoteServiceReference.java
@@ -1,5 +1,19 @@
-/**
- *
+/*
+ * Copyright 2013 Christoph Läubrich
+ *
+ * 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 org.ops4j.pax.swissbox.framework;
@@ -10,7 +24,8 @@
/**
* represents a {@link ServiceReference} in the {@link RemoteFramework}
*/
-public interface RemoteServiceReference {
+public interface RemoteServiceReference
+{
/**
* Fetch the properties of this service reference
@@ -18,11 +33,10 @@
* @param name
* @return
*/
- public Map<String, Object> getProperties(String name);
+ public Map<String, Object> getProperties( String name );
/**
- * @return a filter string that identifies this service in the remote
- * service registry
+ * @return a filter string that identifies this service in the remote service registry
*/
public String getServiceFilter();
}
View
36 .../src/main/java/org/ops4j/pax/swissbox/framework/RemoteServiceReferenceImplementation.java
@@ -1,24 +1,46 @@
+/*
+ * Copyright 2013 Christoph Läubrich
+ *
+ * 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 org.ops4j.pax.swissbox.framework;
import java.io.Serializable;
import java.util.Map;
-public final class RemoteServiceReferenceImplementation implements RemoteServiceReference, Serializable {
+public final class RemoteServiceReferenceImplementation implements RemoteServiceReference,
+ Serializable
+{
- private static final long serialVersionUID = -8634572885337058082L;
+ private static final long serialVersionUID = -8634572885337058082L;
private final Map<String, Object> values;
- private final String serviceFilter;
+ private final String serviceFilter;
- RemoteServiceReferenceImplementation(Map<String, Object> values, String serviceFilter) {
+ RemoteServiceReferenceImplementation( Map<String, Object> values, String serviceFilter )
+ {
this.values = values;
this.serviceFilter = serviceFilter;
}
- public Map<String, Object> getProperties(String name) {
+ public Map<String, Object> getProperties( String name )
+ {
return values;
}
- public String getServiceFilter() {
+ public String getServiceFilter()
+ {
return serviceFilter;
}
-}
+}
Please sign in to comment.
Something went wrong with that request. Please try again.