Interface ServiceBinder<T>
-
- Type Parameters:
T
- the type of the service to bind
public interface ServiceBinder<T>
Provides a binding of corresponding service on corresponding process. Binding a service to it's implementation must be performed via instance of this interface. No one instance of corresponding service could be performed until the binding for
process binder
for which thisservice binder
is created is complete. Instance of corresponding service could not be created when the binding for this instance is not complete. If the binding forprocess binder
for which thisservice binder
is created is complete and the binding for this instance is complete, instance of corresponding service could be created within a corresponding separate process viaIProcessManager.getInstance(String, Class)
. The binding could completed by callingbindTo(Class)
. An instance of this interface could be obtained by callingProcessBinder.getServiceBinder(Class)
.This interface is not designed for implementing. New features may be added to this interface in next versions, and therefore do not create any implementations of this interface. Instance of this interface must be obtained only by calling
ProcessBinder.getServiceBinder(Class)
method.This interface is designed to be thread-safe. Any operations on this instance could be performed until the binding is complete or binding of
process binder
is complete.- See Also:
ProcessBinder
,IProcessManager
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ServiceBinder<T>
addAdditionalClasses(Class<?>... additionalClasses)
Adds all the given additional classes to this binder.ServiceBinder<T>
addAdditionalClassesProvider(IAdditionalClassesProvider additionalClassesProvider)
Adds all the additional classes provided byadditionalClassesProvider
to this binder.ServiceBinder<T>
addLibraries(String... libraries)
Adds all the given libraries to this binder.ServiceBinder<T>
addLibrariesProvider(ILibrariesProvider librariesProvider)
Adds all the libraries provided by givenlibrariesProvider
.ProcessBinder
bindTo(Class<? extends T> implementation)
Completes the binding of service and key (parameters for those this binder was created bygetBinder(key, service)
) with given implementation.Collection<Class<?>>
getAdditionalClasses()
Returns a list of classes to load within separate process to use the implementation.Class<? extends T>
getImplementation()
Returns a bound implementation.String[]
getLibraries()
Returns a list of libraries to load.ProcessBinder
getProcessBinder()
Returns aprocess binder
for which thisservice binder
is created.Class<T>
getService()
Returns a service corresponding to thisservice binder
.boolean
isBound()
Returnstrue
if this binding is complete,false
otherwise.boolean
isSingleton()
Returns whether the service is singleton.ServiceBinder<T>
setSingleton(boolean singleton)
If value of the given parameter istrue
, only one implementation instance will be created within separate process and all the proxy instances of service (created byIProcessManager.getInstance(String, Class)
) will delegate all the method calls to that instance.
-
-
-
Method Detail
-
getProcessBinder
ProcessBinder getProcessBinder()
Returns a
process binder
for which thisservice binder
is created.- Returns:
- a
process binder
for which thisservice binder
is created
-
getService
Class<T> getService()
Returns a service corresponding to this
service binder
.- Returns:
- a service corresponding to this
service binder
-
addLibrariesProvider
ServiceBinder<T> addLibrariesProvider(ILibrariesProvider librariesProvider)
Adds all the libraries provided by given
librariesProvider
. This means that all the provided will be loaded before instantiating bound implementation within separate process. In other words, all this method does is callingaddLibraries(librariesProvider.getLibraries())
This method may be used any number of times within different threads as long as
addLibraries(String...)
until the binding is complete. Calling this method after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed will cause anIllegalStateException
. Binding can be completed by thebindTo(Class)
method.- Parameters:
librariesProvider
- givenlibrariesProvider
(notnull
)- Returns:
- this instance
- Throws:
IllegalStateException
- if called after the binding has been completed
-
addLibraries
ServiceBinder<T> addLibraries(String... libraries)
Adds all the given libraries to this binder. All the given libraries will be loaded within a separate process before an instance of service will be created within a separate process.
This method could be used any number of times within any threads as long as
addLibrariesProvider(ILibrariesProvider)
until the binding is complete. Calling this method after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed will cause anIllegalStateException
. Binding can be completed by thebindTo(Class)
method.- Parameters:
libraries
- given list of libraries (notnull
)- Returns:
- this instance
- Throws:
IllegalStateException
- if called after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed
-
addAdditionalClassesProvider
ServiceBinder<T> addAdditionalClassesProvider(IAdditionalClassesProvider additionalClassesProvider)
Adds all the additional classes provided by
*additionalClassesProvider
to this binder. It means that locations of all the provided classes will be added to separate process's class path and all the provided classes will be added to the main process's context classloader before executing method of some created instance.This method could be used any number of times within any threads as long as
addAdditionalClasses(Class...)
until the binding is complete. Calling this method after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed will cause anIllegalStateException
. Binding can be completed by thebindTo(Class)
method.Note that using this method when the corresponding process is running, it may cause an unexpected effects. For example, all locations of provided classes will not be added to the separate process's classpath that will cause
ClassNotFoundException
at the time these classes will be used. You should not call this method when the corresponding process is running.- Parameters:
additionalClassesProvider
- givenadditionalClassesProvider
(notnull
)- Returns:
- this instance
- Throws:
IllegalStateException
- if called after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed
-
addAdditionalClasses
ServiceBinder<T> addAdditionalClasses(Class<?>... additionalClasses)
Adds all the given additional classes to this binder. It means that locations of all the provided classes will be added to separate process's class path and all the provided classes will be added to the main process's context classloader before executing method of some created instance.
*This method could be used any number of times within any threads until the binding is complete. Calling this method after the binding has been completed or the binding for
process binder
for that thisServiceBinder
is created has been completed will cause anIllegalStateException
. Binding can be completed by thebindTo(Class)
method.Note that using this method when the corresponding process is running, it may cause an unexpected effects. For example, all locations of provided classes will not be added to the separate process's classpath that will cause
ClassNotFoundException
at the time these classes will be used. You should not call this method when the corresponding process is running.- Parameters:
additionalClasses
- given additional classes (notnull
)- Returns:
- this instance
- Throws:
IllegalStateException
- if called after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed
-
setSingleton
ServiceBinder<T> setSingleton(boolean singleton)
If value of the given parameter is
true
, only one implementation instance will be created within separate process and all the proxy instances of service (created byIProcessManager.getInstance(String, Class)
) will delegate all the method calls to that instance. Otherwise, new instance of implementation will be created each timeIProcessManager.getInstance(String, Class)
is invoked.By default, it's set as
false
. There's no need to callsetSingleton(false)
.This method could be used any number of times within any threads until the binding is complete. Calling this method after the binding has been completed or the binding for
process binder
for that thisServiceBinder
is created has been completed will cause anIllegalStateException
. Binding can be completed by thebindTo(Class)
method.- Parameters:
singleton
- given parameter- Returns:
- this instance
- Throws:
IllegalStateException
- if called after the binding has been completed or the binding forprocess binder
for that thisServiceBinder
is created has been completed
-
bindTo
ProcessBinder bindTo(Class<? extends T> implementation)
Completes the binding of service and key (parameters for those this binder was created by
getBinder(key, service)
) with given implementation. Instance of implementation will be created in separate process to create an instance of service within a separate process with key key byIProcessManager.getInstance(String, Class)
method. Instance of service within a separate process with key key could be created if and only if binding is complete, or, in other words, the binding is completed. Therefore, call this method to complete the binding.This method must be called on this instance only once to complete the binding. Any of the operations on this instance instead of
isBound()
are not allowed after the binding has been completed.IllegalStateException
will be thrown if any operation instead ofisBound()
(include this method) is called when the binding is complete or the binding ofprocess binder
for that thisServiceBinder
is created is complete.Throws
IllegalArgumentException
if implementation is not instantiable class or does not have public parameterless constructor.
IfIllegalArgumentException
is thrown, binding is not complete and this method might be called for another time (with another implementation) to complete the binding and any of the operations on this instance still may be called.
Binding is complete if this method is called and did not thrown any exceptions.- Parameters:
implementation
- given implementation of service to bind to service for process with key key. Must be instantiable class. Notnull
.- Returns:
- instance of
ProcessBinder
for that thisservice binder
is created. - Throws:
IllegalStateException
- if called when the binding is complete or the binding forprocess binder
for that thisServiceBinder
is created is completeIllegalArgumentException
- if implementation is not instantiable class or does not have accessible (public) parameterless constructor
-
isBound
boolean isBound()
Returns
true
if this binding is complete,false
otherwise.- Returns:
true
if this binding is complete,false
otherwise
-
getImplementation
Class<? extends T> getImplementation()
Returns a bound implementation. This method is available only after binding is complete (
bindTo(Class)
method is called. Before, it throwsIllegalStateException
.- Returns:
- a bound implementation (not
null
) - Throws:
IllegalArgumentException
- if binding is not completed
-
getLibraries
String[] getLibraries()
Returns a list of libraries to load. This method is available only after binding is complete (
bindTo(Class)
method is called. Before, it throwsIllegalStateException
.- Returns:
- a list of libraries to load (not
null
) - Throws:
IllegalArgumentException
- if binding is not completed
-
isSingleton
boolean isSingleton()
Returns whether the service is singleton. This method is available only after binding is complete (
bindTo(Class)
method is called. Before, it throwsIllegalStateException
.- Returns:
- whether the service is singleton (
true
orfalse
) - Throws:
IllegalArgumentException
- if binding is not completed
-
getAdditionalClasses
Collection<Class<?>> getAdditionalClasses()
Returns a list of classes to load within separate process to use the implementation. This method is available only after binding is complete (
bindTo(Class)
method is called. Before, it throwsIllegalStateException
.- Returns:
- a list of classes to load within separate process to use the implementation (not
null
) - Throws:
IllegalArgumentException
- if binding is not completed
-
-