Class AbstractControllerServer<M extends com.google.protobuf.AbstractMessage,MB extends com.google.protobuf.AbstractMessage.Builder<MB>>
- Type Parameters:
M- the message type of the communication serviceMB- the builder for message M
- All Implemented Interfaces:
org.openbase.jul.extension.protobuf.iface.DataBuilderProvider<M,,MB> org.openbase.jul.extension.type.iface.ScopeProvider,org.openbase.jul.extension.type.iface.TransactionIdProvider,org.openbase.jul.iface.Activatable,org.openbase.jul.iface.Pingable,org.openbase.jul.iface.Readyable,org.openbase.jul.iface.Requestable<M>,org.openbase.jul.iface.Shutdownable,org.openbase.jul.pattern.ChangeListener,org.openbase.jul.pattern.controller.Controller<M>,org.openbase.jul.pattern.controller.MessageController<M,,MB> org.openbase.jul.pattern.provider.DataProvider<M>
- Direct Known Subclasses:
AbstractIdentifiableController
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.openbase.jul.iface.Shutdownable
org.openbase.jul.iface.Shutdownable.ShutdownDaemon -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ReentrantReadWriteLockprotected final kr.pe.kwonnam.slf4jlambda.LambdaLoggerprotected org.openbase.jul.communication.iface.Publisherprotected org.openbase.jul.schedule.WatchDogstatic final Stringprotected org.openbase.type.communication.ScopeType.Scopestatic final Stringstatic final Stringstatic final org.openbase.type.communication.ScopeType.Scopestatic final org.openbase.type.communication.ScopeType.Scopeprotected org.openbase.jul.communication.iface.RPCServerprotected org.openbase.jul.schedule.WatchDogFields inherited from interface org.openbase.jul.extension.type.iface.TransactionIdProvider
TRANSACTION_ID_FIELD_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()voidaddDataObserver(org.openbase.jul.pattern.Observer<org.openbase.jul.pattern.provider.DataProvider<M>, M> observer) voidlongMethod generates a new id which can be used for the next transaction (e.g.org.openbase.jul.extension.protobuf.BuilderSyncSetup<MB> org.openbase.type.domotic.state.AvailabilityStateType.AvailabilityState.StategetData()org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilder(Object consumer) Deprecated.org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilder(Object consumer, org.openbase.jul.extension.protobuf.BuilderSyncSetup.NotificationStrategy notificationStrategy) Deprecated.org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilderInterruptible(Object consumer) org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilderInterruptible(Object consumer, org.openbase.jul.extension.protobuf.BuilderSyncSetup.NotificationStrategy notificationStrategy) protected final ObjectgetDataField(String name) protected final com.google.protobuf.Descriptors.FieldDescriptorgetDataFieldDescriptor(int fieldId) protected org.openbase.jul.schedule.CloseableLockProviderThis method generates a closable lock provider.protected org.openbase.jul.schedule.CloseableReadLockWrappergetManageReadLock(Object consumer) This method generates a closable manager lock wrapper.protected org.openbase.jul.schedule.CloseableReadLockWrappergetManageReadLockInterruptible(Object consumer) This method generates a closable manager lock wrapper.protected org.openbase.jul.schedule.CloseableWriteLockWrappergetManageWriteLock(Object consumer) This method generates a closable manager lock wrapper.protected org.openbase.jul.schedule.CloseableWriteLockWrappergetManageWriteLockInterruptible(Object consumer) This method generates a closable manager lock wrapper.org.openbase.type.communication.ScopeType.ScopegetScope()protected longMethod can be overwritten to delay the controller shutdown.longprotected final booleanhasDataField(String name) voidvoidinit(org.openbase.type.communication.ScopeType.Scope scope) voidinit(org.openbase.type.communication.ScopeType.Scope scope, org.openbase.jul.communication.config.CommunicatorConfig communicatorConfig) booleanisActive()booleanbooleanMethod checks if the requesting thread holds the data builder write lock of this unit.isReady()Method returns true if this instance was initialized, activated and is successfully connected to the middleware.booleanMethod returns true if this instance is currently shutting down.voidSynchronize all registered remote instances about a data change.protected voidnotifyDataUpdate(M data) Overwrite this method to get informed about data updates.protected voidpostInit()Method is called after communication initialization.abstract voidregisterMethods(org.openbase.jul.communication.iface.RPCServer server) Register methods for RPCs on the internal RPC server.voidremoveDataObserver(org.openbase.jul.pattern.Observer<org.openbase.jul.pattern.provider.DataProvider<M>, M> observer) protected final voidsetDataField(int fieldNumber, Object value) protected final voidsetDataField(String fieldName, Object value) voidshutdown()protected final booleansupportsDataField(String name) toString()protected MupdateDataToPublish(MB dataBuilder) Called before publishing data via the publisher.voidMethde sets a new generated transaction id in the global data field of this controller.voidThis method validates the controller activation.voidvoidThis method validates the controller initialisation.voidvoidwaitForAvailabilityState(org.openbase.type.domotic.state.AvailabilityStateType.AvailabilityState.State availabilityState) voidvoidwaitForData(long timeout, TimeUnit timeUnit) voidwaitForMiddleware(long timeout, TimeUnit timeUnit)
-
Field Details
-
SCOPE_ELEMENT_SUFFIX_CONTROL
- See Also:
-
SCOPE_ELEMENT_SUFFIX_STATUS
- See Also:
-
SCOPE_SUFFIX_CONTROL
public static final org.openbase.type.communication.ScopeType.Scope SCOPE_SUFFIX_CONTROL -
SCOPE_SUFFIX_STATUS
public static final org.openbase.type.communication.ScopeType.Scope SCOPE_SUFFIX_STATUS -
RPC_REQUEST_STATUS
- See Also:
-
logger
protected final kr.pe.kwonnam.slf4jlambda.LambdaLogger logger -
publisher
protected org.openbase.jul.communication.iface.Publisher publisher -
server
protected org.openbase.jul.communication.iface.RPCServer server -
publisherWatchDog
protected org.openbase.jul.schedule.WatchDog publisherWatchDog -
serverWatchDog
protected org.openbase.jul.schedule.WatchDog serverWatchDog -
dataLock
-
scope
protected org.openbase.type.communication.ScopeType.Scope scope
-
-
Constructor Details
-
AbstractControllerServer
public AbstractControllerServer(MB builder) throws org.openbase.jul.exception.InstantiationException Create a communication service.- Parameters:
builder- the initial data builder- Throws:
org.openbase.jul.exception.InstantiationException- if the creation fails
-
-
Method Details
-
getShutdownDelay
protected long getShutdownDelay()Method can be overwritten to delay the controller shutdown.- Returns:
- the delay in milliseconds.
-
init
public void init(org.openbase.type.communication.ScopeType.Scope scope) throws org.openbase.jul.exception.InitializationException, InterruptedException - Parameters:
scope-- Throws:
org.openbase.jul.exception.InitializationExceptionInterruptedException
-
init
public void init(String scope) throws org.openbase.jul.exception.InitializationException, InterruptedException - Parameters:
scope-- Throws:
org.openbase.jul.exception.InitializationExceptionInterruptedException
-
init
public void init(org.openbase.type.communication.ScopeType.Scope scope, org.openbase.jul.communication.config.CommunicatorConfig communicatorConfig) throws org.openbase.jul.exception.InitializationException, InterruptedException - Parameters:
scope-communicatorConfig-- Throws:
org.openbase.jul.exception.InitializationExceptionInterruptedException
-
postInit
protected void postInit() throws org.openbase.jul.exception.InitializationException, InterruptedExceptionMethod is called after communication initialization. You can overwrite this method to trigger any component specific initialization.- Throws:
org.openbase.jul.exception.InitializationExceptionInterruptedException
-
getDataClass
-
activate
public void activate() throws InterruptedException, org.openbase.jul.exception.CouldNotPerformException- Specified by:
activatein interfaceorg.openbase.jul.iface.Activatable
-
deactivate
public void deactivate() throws InterruptedException, org.openbase.jul.exception.CouldNotPerformException- Specified by:
deactivatein interfaceorg.openbase.jul.iface.Activatable
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceorg.openbase.jul.iface.Shutdownable
-
isActive
public boolean isActive()- Specified by:
isActivein interfaceorg.openbase.jul.iface.Activatable- Returns:
-
getData
-
getDataFuture
- Specified by:
getDataFuturein interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Returns:
-
waitForAvailabilityState
public void waitForAvailabilityState(org.openbase.type.domotic.state.AvailabilityStateType.AvailabilityState.State availabilityState) throws InterruptedException - Specified by:
waitForAvailabilityStatein interfaceorg.openbase.jul.pattern.controller.Controller<M extends com.google.protobuf.AbstractMessage>
-
cloneDataBuilder
-
getBuilderSetup
-
getDataBuilder
@Deprecated public org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilder(Object consumer) Deprecated. -
getDataBuilder
@Deprecated public org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilder(Object consumer, org.openbase.jul.extension.protobuf.BuilderSyncSetup.NotificationStrategy notificationStrategy) Deprecated. -
getDataBuilderInterruptible
public org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilderInterruptible(Object consumer) throws InterruptedException - Specified by:
getDataBuilderInterruptiblein interfaceorg.openbase.jul.extension.protobuf.iface.DataBuilderProvider<M extends com.google.protobuf.AbstractMessage,MB extends com.google.protobuf.AbstractMessage.Builder<MB>> - Parameters:
consumer-- Returns:
- Throws:
InterruptedException
-
getDataBuilderInterruptible
public org.openbase.jul.extension.protobuf.ClosableDataBuilder<MB> getDataBuilderInterruptible(Object consumer, org.openbase.jul.extension.protobuf.BuilderSyncSetup.NotificationStrategy notificationStrategy) throws InterruptedException - Specified by:
getDataBuilderInterruptiblein interfaceorg.openbase.jul.extension.protobuf.iface.DataBuilderProvider<M extends com.google.protobuf.AbstractMessage,MB extends com.google.protobuf.AbstractMessage.Builder<MB>> - Parameters:
consumer-notificationStrategy-- Returns:
- Throws:
InterruptedException
-
getManageWriteLock
This method generates a closable manager lock wrapper. Be informed that the controller and all its services are directly locked and internal builder operations are queued. Therefore please call the close method soon as possible to release the lock after you are done, otherwise the overall processing pipeline is delayed.Note: Be aware that your access is time limited an the lock will auto released if locked in longer term. This is a recovering feature but should never be used by design!
In this example the CloseableWriteLockWrapper.close method is be called in background after leaving the try brackets.Usage Example: try(final CloseableWriteLockWrapper ignored = getManageWriteLock(this)) { // do important stuff... }- Parameters:
consumer- a responsible instance which consumes the lock.- Returns:
- a new builder wrapper which already locks the manage lock.
-
getManageReadLock
This method generates a closable manager lock wrapper. Be informed that the controller and all its services are directly locked and internal builder operations are queued. Therefore please call the close method soon as possible to release the lock after you are done, otherwise the overall processing pipeline is delayed.Note: Be aware that your access is time limited an the lock will auto released if locked in longer term. This is a recovering feature but should never be used by design!
In this example the CloseableWriteLockWrapper.close method is be called in background after leaving the try brackets.Usage Example: try(final CloseableReadLockWrapper ignored = getManageReadLock(this)) { // do important stuff... }- Parameters:
consumer- a responsible instance which consumes the lock.- Returns:
- a new builder wrapper which already locks the manage lock.
-
getManageWriteLockInterruptible
protected org.openbase.jul.schedule.CloseableWriteLockWrapper getManageWriteLockInterruptible(Object consumer) throws InterruptedException This method generates a closable manager lock wrapper. Be informed that the controller and all its services are directly locked and internal builder operations are queued. Therefore please call the close method soon as possible to release the lock after you are done, otherwise the overall processing pipeline is delayed.Note: Be aware that your access is time limited an the lock will auto released if locked in longer term. This is a recovering feature but should never be used by design!
In this example the CloseableWriteLockWrapper.close method is be called in background after leaving the try brackets.Usage Example: try(final CloseableInterruptibleWriteLockWrapper ignored = getManageWriteLock(this)) { // do important stuff... }- Parameters:
consumer- a responsible instance which consumes the lock.- Returns:
- a new builder wrapper which already locks the manage lock.
- Throws:
InterruptedException- in case the thread was externally interrupted during the locking.
-
getManageReadLockInterruptible
protected org.openbase.jul.schedule.CloseableReadLockWrapper getManageReadLockInterruptible(Object consumer) throws InterruptedException This method generates a closable manager lock wrapper. Be informed that the controller and all its services are directly locked and internal builder operations are queued. Therefore please call the close method soon as possible to release the lock after you are done, otherwise the overall processing pipeline is delayed.Note: Be aware that your access is time limited an the lock will auto released if locked in longer term. This is a recovering feature but should never be used by design!
In this example the CloseableWriteLockWrapper.close method is be called in background after leaving the try brackets.Usage Example: try(final CloseableInterruptibleReadLockWrapper ignored = getManageReadLock(this)) { // do important stuff... }- Parameters:
consumer- a responsible instance which consumes the lock.- Returns:
- a new builder wrapper which already locks the manage lock.
- Throws:
InterruptedException- in case the thread was externally interrupted during the locking.
-
getManageLock
protected org.openbase.jul.schedule.CloseableLockProvider getManageLock()This method generates a closable lock provider. Be informed that the controller and all its services are directly locked and internal builder operations are queued. Therefore please release the locks after usage, otherwise the overall processing pipeline is delayed.Note: Be aware that your access is time limited an the lock will auto released if locked in longer term. This is a recovering feature but should never be used by design!
- Returns:
- a provider to access the manage read and write lock.
-
getScope
public org.openbase.type.communication.ScopeType.Scope getScope() throws org.openbase.jul.exception.NotAvailableException- Specified by:
getScopein interfaceorg.openbase.jul.extension.type.iface.ScopeProvider- Returns:
-
notifyChange
public void notifyChange() throws org.openbase.jul.exception.CouldNotPerformException, InterruptedExceptionSynchronize all registered remote instances about a data change.- Specified by:
notifyChangein interfaceorg.openbase.jul.pattern.ChangeListener- Specified by:
notifyChangein interfaceorg.openbase.jul.pattern.controller.Controller<M extends com.google.protobuf.AbstractMessage>- Throws:
org.openbase.jul.exception.CouldNotPerformExceptionInterruptedException
-
updateDataToPublish
protected M updateDataToPublish(MB dataBuilder) throws org.openbase.jul.exception.CouldNotPerformException Called before publishing data via the publisher. Can be implemented by sub classes to update data which can be received by everyone.- Parameters:
dataBuilder- a clone of the current data builder.- Returns:
- a message build from the data builder
- Throws:
org.openbase.jul.exception.CouldNotPerformException- if the update fails
-
notifyDataUpdate
Overwrite this method to get informed about data updates.- Parameters:
data- new arrived data messages.- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
setDataField
protected final void setDataField(int fieldNumber, Object value) throws org.openbase.jul.exception.CouldNotPerformException - Parameters:
fieldNumber-value-- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
setDataField
protected final void setDataField(String fieldName, Object value) throws org.openbase.jul.exception.CouldNotPerformException - Parameters:
fieldName-value-- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
getDataField
protected final Object getDataField(String name) throws org.openbase.jul.exception.NotAvailableException - Parameters:
name-- Returns:
- Throws:
org.openbase.jul.exception.NotAvailableException
-
hasDataField
protected final boolean hasDataField(String name) throws org.openbase.jul.exception.CouldNotPerformException - Parameters:
name-- Returns:
- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
supportsDataField
protected final boolean supportsDataField(String name) throws org.openbase.jul.exception.CouldNotPerformException - Parameters:
name-- Returns:
- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
getDataFieldDescriptor
protected final com.google.protobuf.Descriptors.FieldDescriptor getDataFieldDescriptor(int fieldId) - Parameters:
fieldId-- Returns:
-
getControllerAvailabilityState
public org.openbase.type.domotic.state.AvailabilityStateType.AvailabilityState.State getControllerAvailabilityState()- Specified by:
getControllerAvailabilityStatein interfaceorg.openbase.jul.pattern.controller.Controller<M extends com.google.protobuf.AbstractMessage>- Returns:
-
validateInitialization
public void validateInitialization() throws org.openbase.jul.exception.NotInitializedException, InterruptedExceptionThis method validates the controller initialisation.- Throws:
org.openbase.jul.exception.NotInitializedException- is thrown if the controller is not initialized.InterruptedException- is thrown in case the thread was externally interrupted.
-
validateActivation
public void validateActivation() throws org.openbase.jul.exception.InvalidStateExceptionThis method validates the controller activation.- Throws:
org.openbase.jul.exception.InvalidStateException- is thrown if the controller is not active.
-
validateMiddleware
public void validateMiddleware() throws org.openbase.jul.exception.InvalidStateException- Throws:
org.openbase.jul.exception.InvalidStateException
-
waitForMiddleware
public void waitForMiddleware(long timeout, TimeUnit timeUnit) throws InterruptedException, org.openbase.jul.exception.CouldNotPerformException - Throws:
InterruptedExceptionorg.openbase.jul.exception.CouldNotPerformException
-
isDataBuilderWriteLockedByCurrentThread
public boolean isDataBuilderWriteLockedByCurrentThread()Method checks if the requesting thread holds the data builder write lock of this unit. This check can help to decide if a notification should be performed or not since releasing the write lock mostly notifies anyway depending on the selected notification strategy.- Returns:
- true if the current thread hold the builder write lock, otherwise false.
-
ping
- Specified by:
pingin interfaceorg.openbase.jul.iface.Pingable- Parameters:
timestamp-- Returns:
-
requestStatus
- Specified by:
requestStatusin interfaceorg.openbase.jul.iface.Requestable<M extends com.google.protobuf.AbstractMessage>- Returns:
-
registerMethods
public abstract void registerMethods(org.openbase.jul.communication.iface.RPCServer server) throws org.openbase.jul.exception.CouldNotPerformException Register methods for RPCs on the internal RPC server.- Parameters:
server- the rpc server on which the methods should be registered.- Throws:
org.openbase.jul.exception.CouldNotPerformException- if registering methods fails
-
isDataAvailable
public boolean isDataAvailable()- Specified by:
isDataAvailablein interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Returns:
-
isReady
Method returns true if this instance was initialized, activated and is successfully connected to the middleware.- Specified by:
isReadyin interfaceorg.openbase.jul.iface.Readyable- Returns:
- returns true if this instance is ready otherwise false.
-
waitForData
public void waitForData() throws org.openbase.jul.exception.CouldNotPerformException, InterruptedException- Specified by:
waitForDatain interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>
-
waitForData
public void waitForData(long timeout, TimeUnit timeUnit) throws org.openbase.jul.exception.CouldNotPerformException, InterruptedException - Specified by:
waitForDatain interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Parameters:
timeout-timeUnit- .
-
addDataObserver
public void addDataObserver(org.openbase.jul.pattern.Observer<org.openbase.jul.pattern.provider.DataProvider<M>, M> observer) - Specified by:
addDataObserverin interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Parameters:
observer-
-
removeDataObserver
public void removeDataObserver(org.openbase.jul.pattern.Observer<org.openbase.jul.pattern.provider.DataProvider<M>, M> observer) - Specified by:
removeDataObserverin interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Parameters:
observer-
-
getTransactionId
public long getTransactionId()- Specified by:
getTransactionIdin interfaceorg.openbase.jul.extension.type.iface.TransactionIdProvider- Returns:
-
generateTransactionId
public long generateTransactionId()Method generates a new id which can be used for the next transaction (e.g. state transition).- Returns:
- the next transaction identifier.
-
updateTransactionId
public void updateTransactionId() throws org.openbase.jul.exception.CouldNotPerformExceptionMethde sets a new generated transaction id in the global data field of this controller.- Throws:
org.openbase.jul.exception.CouldNotPerformException
-
validateData
public void validateData() throws org.openbase.jul.exception.InvalidStateException- Specified by:
validateDatain interfaceorg.openbase.jul.pattern.provider.DataProvider<M extends com.google.protobuf.AbstractMessage>- Throws:
org.openbase.jul.exception.InvalidStateException
-
isShutdownInProgress
public boolean isShutdownInProgress()Method returns true if this instance is currently shutting down. -
toString
-