|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.softamis.cluster4spring.support.context.AbstractServicePublisher<EC>
EC
- type of service exporter which is supported by publisherpublic abstract class AbstractServicePublisher<EC extends AutoDiscoveredServiceExporter>
Abstract base implementation of service publisher. During refreshing application context, publisher collects all service exporters with needed class and if they are applicable for service publishing, it publishes information about these services in distributed registry. Therefore, clients that requires autodiscoverable services may obtain information about service urls and so use them.
To determine whether particular service exporter should be published by this publisher,
delegates actual logic to associated ExporterAcceptor
.
On closing service context, publisher notifies distributed registry for unregistration of all service urls previosly published by publisher.
While there is ready to use implementation of this class wich uses distributed registry is included into part of the library, it's possible to use other implementation of distributed services storage. If it's desired to use another storage (say, JBoss Cache), this class should be considered as base one for implementing such integration.
ExporterAcceptor
Field Summary | |
---|---|
protected java.lang.Class<EC> |
fAutodiscoveredExporterClass
Class of exporter should be published |
protected java.util.List<ServiceInfo> |
fAutodiscoveredServicesInfo
Cache of discovered services |
protected java.lang.String |
fBeanName
Name of bean - used in logging |
protected boolean |
fCacheAutoDiscoveredServicesInfo
Indicates whether services discovered for publishing during context refreshing should be cached until context closing |
protected org.springframework.context.ApplicationContext |
fContext
Application context |
protected ExporterAcceptor<EC,ServicePublisher> |
fExporterAcceptor
ExporterAcceptor used to determine whether service exported by particular exporter could be published |
protected java.lang.String |
fProtocolName
Name of protocol |
protected long |
fServerID
If there are several servers of the same type exists withing the same cluster, it is necessary to distinguish them. |
protected java.lang.String |
fServerType
Type of server. |
protected java.lang.String |
fServiceGroup
Services group |
Fields inherited from interface org.softamis.cluster4spring.ServicePublisher |
---|
SERVER_TYPE_DELIMITER |
Constructor Summary | |
---|---|
protected |
AbstractServicePublisher()
Creates publisher |
Method Summary | |
---|---|
void |
afterPropertiesSet()
Called by Spring as part of bean lifecycle. |
protected java.util.List<ServiceInfo> |
collectAutoDiscoveredServices()
Collects information about services that could be published. |
protected void |
contextClosed()
Handles closing application context. |
protected void |
contextRefreshed()
Handles refreshing of application context. |
protected ExporterAcceptor<EC,ServicePublisher> |
createDefaultExporterAcceptor()
Creates ExporterAcceptor that will be used if ones is not specified explicitely. |
protected java.util.List<ServiceInfo> |
createServiceInfos(java.lang.String aBeanName,
EC aExporter)
Creates information about service based on given service exporter. |
protected ServiceMoniker |
createServiceMoniker(ServiceInfo aServiceInfo)
Creates ServiceMoniker by given discovered ServiceInfo |
protected java.lang.String |
createServicesGroup()
Creates default name for services group if one is not specified explicitely. |
protected java.util.Map<java.lang.String,EC> |
doGetAutoDiscoveredServices(java.lang.Class aExporterClass)
Collects exporters that potentially published from application context Current implementation simply selects all beans from Spring Context with provided class |
protected abstract void |
doRegisterServiceInServicesRegistry(java.lang.String aServiceKey,
ServiceMoniker aMoniker)
Notifies underlying services registry that information about service should be published |
protected abstract void |
doUnregisterServiceInServicesRegistry(java.lang.String aServiceKey)
Notifies that service under given key should be unregistered in underlying services registry |
protected java.lang.Class<EC> |
getAutodiscoveredExporterClass()
Return class of servicie exporter that is used to select information about services which should be published by this publisher |
protected java.lang.String |
getProtocolName()
Returns name of protocol used exporters. |
protected java.lang.String |
getPublisherName()
Return name of the bean in bean factory |
long |
getServerID()
If there are several servers of the same type exists withing the same cluster, it is necessary to distinguish them. |
java.lang.String |
getServerType()
Returns type of server. |
java.lang.String |
getServiceGroup()
Returns services group |
protected java.lang.String |
getServiceKey(ServiceInfo aServiceInfo)
Creates key for published service. |
boolean |
isCacheAutoDiscoveredServicesInfo()
Specifies whether information about published services should be cached until context closing |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent aEvent)
Handles Spring application event. |
protected java.lang.String |
prepareServiceURL(java.lang.String aServiceUrl)
Prepared URL for service. |
protected void |
publishService(ServiceInfo aServiceInfo)
Performs publishing of service denoted by given parameter by notifying underlying services registry. |
void |
publishServices()
Collects and publishes all applicable services for auto-discovering. |
void |
setApplicationContext(org.springframework.context.ApplicationContext aContext)
|
void |
setBeanName(java.lang.String aName)
Set the aName of the bean in the bean factory that created this bean. |
void |
setCacheAutoDiscoveredServicesInfo(boolean aCache)
Specifies whether information about published services should be cached until context closing. |
void |
setExporterAcceptor(ExporterAcceptor<EC,ServicePublisher> aExporterAcceptor)
Sets exporterAcceptor used to determine whether service exported by particular exporter could be published |
void |
setServerID(long aServerID)
Setter for ServerID property |
void |
setServerType(java.lang.String aServerType)
Setter for server types. |
void |
setServiceGroup(java.lang.String aServiceGroup)
Sets services group. |
protected void |
unPublishService(ServiceInfo serviceInfo)
Performs un-publishing of service denoted by given parameter by notifying underlying services registry. |
void |
unPublishServices()
Removes information about own published services from auto-discovering context. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected org.springframework.context.ApplicationContext fContext
protected java.lang.String fServiceGroup
protected boolean fCacheAutoDiscoveredServicesInfo
protected java.util.List<ServiceInfo> fAutodiscoveredServicesInfo
protected ExporterAcceptor<EC extends AutoDiscoveredServiceExporter,ServicePublisher> fExporterAcceptor
protected java.lang.String fBeanName
protected java.lang.String fServerType
protected long fServerID
protected java.lang.Class<EC extends AutoDiscoveredServiceExporter> fAutodiscoveredExporterClass
protected java.lang.String fProtocolName
Constructor Detail |
---|
protected AbstractServicePublisher()
Method Detail |
---|
public void setBeanName(java.lang.String aName)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
aName
- aName of the beanprotected java.lang.String getPublisherName()
public void onApplicationEvent(org.springframework.context.ApplicationEvent aEvent)
onApplicationEvent
in interface org.springframework.context.ApplicationListener
aEvent
- event from SpringcontextRefreshed()
,
contextClosed()
protected java.util.List<ServiceInfo> collectAutoDiscoveredServices()
createServiceInfos(String,AutoDiscoveredServiceExporter)
,
ExporterAcceptor
,
getAutodiscoveredExporterClass()
protected java.util.Map<java.lang.String,EC> doGetAutoDiscoveredServices(java.lang.Class aExporterClass) throws org.springframework.beans.BeansException
aExporterClass
- class of exporter
org.springframework.beans.BeansException
- thrown by Spring ApplicationContext during obtainig list of beansprotected void contextClosed() throws java.lang.Exception
java.lang.Exception
- throw if exception occured during closing contextonApplicationEvent(org.springframework.context.ApplicationEvent)
protected void contextRefreshed() throws java.lang.Exception
java.lang.Exception
onApplicationEvent(org.springframework.context.ApplicationEvent)
protected java.lang.String getServiceKey(ServiceInfo aServiceInfo)
DiscoveringServiceProvider
.
Current implementation created key in form SERVICE_GROUP/SERVICE_NAME.
aServiceInfo
- information about exported service.
public void unPublishServices()
unPublishServices
in interface ServicePublisher
collectAutoDiscoveredServices()
,
getServiceKey(ServiceInfo)
public void publishServices()
publishServices
in interface ServicePublisher
collectAutoDiscoveredServices()
,
getServiceKey(ServiceInfo)
protected void unPublishService(ServiceInfo serviceInfo)
serviceInfo
- key used to denote service which should be unpublishedprotected void publishService(ServiceInfo aServiceInfo)
aServiceInfo
- key used to denote service which should be publishedprotected ServiceMoniker createServiceMoniker(ServiceInfo aServiceInfo)
ServiceMoniker
by given discovered ServiceInfo
aServiceInfo
- collected information about service
ServiceMoniker
public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
createServicesGroup()
,
createDefaultExporterAcceptor()
protected ExporterAcceptor<EC,ServicePublisher> createDefaultExporterAcceptor()
DefaultExporterAcceptor
protected java.lang.String createServicesGroup()
AutoDiscoveredServiceExporter.DEFAULT_SERVICES_GROUP_PREFIX + getProtocolName()
public void setApplicationContext(org.springframework.context.ApplicationContext aContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public java.lang.String getServiceGroup()
getServiceGroup
in interface ServicePublisher
GroupBasedExporterAcceptor
public void setServiceGroup(java.lang.String aServiceGroup)
aServiceGroup
- services grouppublic boolean isCacheAutoDiscoveredServicesInfo()
true
if caching is requiredpublic void setCacheAutoDiscoveredServicesInfo(boolean aCache)
false
aCache
- true if autodiscovered services should be cached until unpublishingpublic void setExporterAcceptor(ExporterAcceptor<EC,ServicePublisher> aExporterAcceptor)
aExporterAcceptor
- exporterAcceptorpublic java.lang.String getServerType()
public void setServerType(java.lang.String aServerType)
aServerType
- type of serverpublic long getServerID()
public void setServerID(long aServerID)
aServerID
- protected java.util.List<ServiceInfo> createServiceInfos(java.lang.String aBeanName, EC aExporter)
aBeanName
- name of beanaExporter
- exporter
protected java.lang.String prepareServiceURL(java.lang.String aServiceUrl)
aServiceUrl
- url of service
ServiceMoniker
protected java.lang.String getProtocolName()
protected java.lang.Class<EC> getAutodiscoveredExporterClass()
protected abstract void doUnregisterServiceInServicesRegistry(java.lang.String aServiceKey)
aServiceKey
- key for service that should be unregisteredprotected abstract void doRegisterServiceInServicesRegistry(java.lang.String aServiceKey, ServiceMoniker aMoniker)
aServiceKey
- key for serviceaMoniker
- service information
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |