org.eclipse.osgi.framework.console
Class ConsoleSession

java.lang.Object
  extended by org.eclipse.osgi.framework.console.ConsoleSession
All Implemented Interfaces:
ServiceFactory<java.lang.Object>
Direct Known Subclasses:
FrameworkConsoleSession

public abstract class ConsoleSession
extends java.lang.Object
implements ServiceFactory<java.lang.Object>

A console session service provides the input and output to a single console session. The input will be used by the console to read in console commands. The output will be used to print the results of console commands.

The console session must be registered as an OSGi service in order to be associated with a console instance. The console implementation will discover any console session services and will create a new console instance using the console session for input and output. When a session is closed then the console session service will be unregistered and the console instance will terminate and be disposed of. The console instance will also terminate if the console session service is unregistered for any reason.

Since:
3.6

Constructor Summary
ConsoleSession()
           
 
Method Summary
 void close()
          Called by the console implementation to free resources associated with this console session.
protected abstract  void doClose()
          Called by the close() method to free resources associated with this console session.
abstract  java.io.InputStream getInput()
          Returns the input for this console session.
abstract  java.io.OutputStream getOutput()
          Returns the output for this console session.
 java.lang.Object getService(Bundle bundle, ServiceRegistration<java.lang.Object> registration)
          Creates a new service object.
 void ungetService(Bundle bundle, ServiceRegistration<java.lang.Object> registration, java.lang.Object service)
          Releases a service object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConsoleSession

public ConsoleSession()
Method Detail

close

public final void close()
Called by the console implementation to free resources associated with this console session. This method will result in the console session service being unregistered from the service registry.


doClose

protected abstract void doClose()
Called by the close() method to free resources associated with this console session. For example, closing the streams associated with the input and output for this session.


getInput

public abstract java.io.InputStream getInput()
Returns the input for this console session. This input will be used to read console commands from the user of the session.

Returns:
the input for this console session

getOutput

public abstract java.io.OutputStream getOutput()
Returns the output for this console session. This output will be used to write the results of console commands.

Returns:
the output for this console session.

getService

public final java.lang.Object getService(Bundle bundle,
                                         ServiceRegistration<java.lang.Object> registration)
Description copied from interface: ServiceFactory
Creates a new service object.

The Framework invokes this method the first time the specified bundle requests a service object using the BundleContext.getService(ServiceReference) method. The service factory can then return a specific service object for each bundle.

The Framework must check that the returned service object is valid. If the returned service object is null or is not an instanceof all the classes named when the service was registered, a framework event of type FrameworkEvent.ERROR is fired containing a service exception of type ServiceException.FACTORY_ERROR and null is returned to the bundle. If this method throws an exception, a framework event of type FrameworkEvent.ERROR is fired containing a service exception of type ServiceException.FACTORY_EXCEPTION with the thrown exception as the cause and null is returned to the bundle. If this method is recursively called for the specified bundle, a framework event of type FrameworkEvent.ERROR is fired containing a service exception of type ServiceException.FACTORY_RECURSION and null is returned to the bundle.

The Framework caches the valid service object and will return the same service object on any future call to BundleContext.getService for the specified bundle. This means the Framework must not allow this method to be concurrently called for the specified bundle.

Specified by:
getService in interface ServiceFactory<java.lang.Object>
Parameters:
bundle - The bundle requesting the service.
registration - The ServiceRegistration object for the requested service.
Returns:
A service object that must be an instance of all the classes named when the service was registered.
See Also:
BundleContext.getService(org.osgi.framework.ServiceReference)

ungetService

public final void ungetService(Bundle bundle,
                               ServiceRegistration<java.lang.Object> registration,
                               java.lang.Object service)
Description copied from interface: ServiceFactory
Releases a service object.

The Framework invokes this method when a service has been released by a bundle. The service object may then be destroyed.

If this method throws an exception, a framework event of type FrameworkEvent.ERROR is fired containing a service exception of type ServiceException.FACTORY_EXCEPTION with the thrown exception as the cause.

Specified by:
ungetService in interface ServiceFactory<java.lang.Object>
Parameters:
bundle - The bundle releasing the service.
registration - The ServiceRegistration object for the service being released.
service - The service object returned by a previous call to the getService method.
See Also:
BundleContext.ungetService(org.osgi.framework.ServiceReference)


Copyright © 2007-2012 FuseSource, Corp.. All Rights Reserved.