Examples of configurationThis section contains several examples of configuring various schemes of Cluster4Spring remoting via Spring configuration files. Please note that it is possible to use two forms of remote proxy factory configuration - one that uses generic proxy factory class or one that uses concrete classes of remote proxy factories (shorter form). Generic Configuration of Remote ProxyWhile it is possible to implement different schemes of remoting using Cluster4Spring, several common configuration options are common to all remoting schemes. In this section, we go into details about these options and later we will highlight only the specifics of every particular remoting scheme. The following listing illustrates how to configure generic remote proxy factory bean (providing that RMI is used as underlying remoting protocol). This example uses generic form of remote proxy factory bean that is applicable to every remoting scheme and is parameterized by appropriated endpoints provider (to support specifics of particular remoting scheme). There is shorter form of proxy factory declaration that requires shorter markup and combines both definition of proxy with definition of EndpointProvider. Examples of such scheme usage will be shown later. Please refer to configuration comments below to find more information for every particular element of declaration. [1]� <bean name="TestService.verbose" ���������� class="org.softamis.cluster4spring.rmi.RmiProxyFactoryBean"> [2]��� <property name="serviceInterface" ��������������� �value="org.softamis.cluster4spring.example.Service"/> [3]��� <property name="refreshEndpointsOnStartup" value="true"/> [4]��� <property name="refreshEndpointsOnConnectFailure" value="true"/> [5]��� <property name="switchEndpointOnFailure" value="false"/> [6]��� <property name="registerTraceInterceptor" value="true"/> [7]�� �<property name="remoteInvocationTraceInterceptor"> ��� ������<bean class="..."> ������������ ...��� ������ </bean> </property> [8] ���<property name="endpointProvider"> ���� ����... �� ������...� ����� </property> [9] ���<property name="interceptorNames" value="_Interceptor1, _Interceptor2"/> [10] ��<property name="endpointFactory"> ���� �����<bean class="org.softamis.cluster4spring.rmi.support.RmiEndpointFactory"/> </property> [11] ��<property name="remoteInvocationFactory"> <bean class="org.springframework.support.DefaultRemoteInvocationFactory"/>�� ���� </property> </bean> Configuration details:
The listing above illustrates all properties that can be configured. However, most of them are optional and should be specified only if this is necessary for particular application. Generic Configuration of Service ExporterIn general, using ServiceExporter implementation included into Cluster4Spring is required only if "one-to-many with dynamic services discovering" remoting scheme is used. For all other cases, it is possible to use standard services exporter provided by Spring. However, service exporter included in Cluster4Spring offers some additional functionality in comparison with Spring based one, which can be useful for particular applications. The following listing illustrates generic configuration of service exporter (assuming that RMI is used as underlying remoting protocol). Please refer to configuration comments below to find more information on every element of declaration. [1]<bean name="TestService.custom.verbose" ���� ����class="org.softamis.cluster4spring.rmi.RmiServiceExporter"> [2]� <property name="allowsAutoDiscovering" value="false"/> [3]� <property name="clientSocketFactory" ref="_RMIClientSocketsFactory"/> [4]� <property name="interceptorNames" value="_Interceptor1, _Interceptor2"/> [5] �<property name="registerTraceInterceptor" value="true"/> [6]� <property name="remoteInvocationExecutor" ref="_RemoteInvocationExecutor"/> [7]� <property name="remoteInvocationTraceInterceptor"> �� �����<bean class="..."> �� �������... � ����� </bean> ��</property> [8]� <property name="registry" ref="_RMIRegistry"/> [9]� <property name="service" ref="TestService.bean"/> [10] <property name="serviceInterface" ������������� �value="org.softamis.cluster4spring.example.Service"/> [11] <property name="serviceName"value="TestService"/> � </bean> Configuration comments:
The listing above illustrates all properties that can be configured. However, most of them are optional and should be specified only if this is necessary for particular application. Configuring one-to-one remotingWe provide example of one-to-one remoting scheme configuration. For simplicity's sake, only client-side configuration of remoting is shown. On the server side, for this remoting scheme either standard Spring exporter or Cluster4Spring one can be used. In general, configuring proxy factory for one-to-one remoting scheme is very simple and is illustrated by examples below. Using specialized factory beanThe listing below illustrates minimal configuration with specialized proxy factory bean that is used to implement one-to-one scheme of remoting. Please refer to configuration comments below to find more information on every element of declaration. [1]<bean name="TestService.compact.minimal"� � �������class="org.softamis.cluster4spring.rmi.RmiSingleUrlProxyFactoryBean"> [2]�� <property name="serviceInterface" �������������� value="org.softamis.cluster4spring.example.Service"/> [3]�� <property name="serviceUrl" value="rmi://localhost:1099/TestService"/> � �</bean> Configuration comments:
Of course, it is possible to configure all generic properties as it shown above. Using generic proxy factory beanIf the use of generic exporter is more preferable for some reasons, it possible to implement different configuration (which is functionally equivalent to one listed above) that utilizes generic exporter customized by specific EndpointProvider. The following listing illustrates examples of such configuration. Please refer to configuration comments below to find more information on every element of declaration. [1]<bean name="TestService.verbose.minimal" class="org.softamis.cluster4spring.rmi.RmiProxyFactoryBean"> [2] <property name="serviceInterface" ������������ �value="org.softamis.cluster4spring.example.Service"/> [3] <property name="endpointProvider"> [4]�� <bean class="org.softamis.cluster4spring.support.provider.SingleUrlEndpointProvider"> [5]���� <property name="serviceUrl" value="rmi://localhost:1099/TestService"/> �� ���</bean> � ��</property> � </bean> Configuration comments:
Configuring static one-to-many remotingIn this section we provide an example of configuration for "static one-to-many" remoting scheme that assumes that remote service is available in several known remoting locations. For simplicity's sake, here we illustrate only configuration that should be performed on client side. On the server side, for this remoting scheme either standard Spring exporter or Cluster4Spring one can be used. Configuring proxy factory for such remoting scheme is also quite simple and is illustrated by listings below. Using specialized proxy factory beanThe listing below illustrates minimal configuration with specialized proxy factory bean that is used to implement static one-to-may scheme of remoting. Please refer to configuration comments below to find more information on every particular element of declaration. [1]<bean name="TestService.compact.minimal" class="org.softamis.cluster4spring.rmi.RmiUrlListProxyFactoryBean"> [2] <property name="serviceInterface" ������������ value="org.softamis.cluster4spring.example.Service"/> [3] <property name="serviceURLs"> ����� <list> ������� <value>rmi://localhost:1097/TestService</value> ������� <value>rmi://localhost:1098/TestService</value> ������� <value>rmi://localhost:1099/TestService</value> ����� </list> ��� </property> [4] <property name="endpointSelectionPolicy"> ����� <bean class="org.softamis.cluster4spring.support.invocation.DefaultEndpointSelectionPolicy"/> ��� </property> � </bean> Configuration comments:
Again, it is possible to configure all generic properties as it shown above. Using generic proxy factory beanIf, for some reasons, using generic exporter is more preferable, it possible to use a different configuration (which is functionally equivalent to the listing above) that utilizes generic exporter customized by specific EndpointProvider. The following listing illustrates such a configuration. Please refer to configuration comments below to find more information on every particular element of declaration. [1]<bean name="TestService.verbose.minimal" class="org.softamis.cluster4spring.rmi.RmiProxyFactoryBean"> [2]� <property name="serviceInterface" ������������� value="org.softamis.cluster4spring.example.Service"/> [3]� <property name="endpointProvider"> [4]� ���<bean class="org.softamis.cluster4spring.support.provider.UrlListEndpointProvider"> [5]�� �����<property name="serviceURLs"> ������� ����<list> ��������� ����<value>rmi://localhost:1097/TestService</value> ����������� ��<value>rmi://localhost:1098/TestService</value> � ������������<value>rmi://localhost:1099/TestService</value> � ����������</list> ��� �������</property> � ������</bean> � ���</property> � �</bean> Configuration comments:
Configuring one-to-many remoting with dynamic services discoveringThis scheme requires more complicated configuration. However, that complexity doesn't relate to declaration of client proxy and service exporter, but rather is related to necessary additional configuration of distributed registry. The following examples assume that DistRegistry implementation of distributed registry is used as well as appropriate implementations of endpoint providers and publisher that utilize DistRegistry. However, it is possible to create custom endpoint providers and publishers that will utilize different implementation of distributed services registry. Please refer to documentation for DistRegistry (included into Cluster4Spring distributive or available from this site) to get more details on how to configure distributed registry. Client part of distributed services registryBefore configuring the remote proxy factory itself, it is necessary to configure the distributed services registry used for services discovering. The following listing illustrates configuration for distributed services registry. Please refer to configuration comments below to get more information on every particular element of declaration. [1]� <beanid="_ClientServicesRegistry" �� ������� class="org.softamis.net.registry.spring.DefaultConsumingRegistry"> [2]��� <property name="communicationHelper"> [3]��� ���<bean class="org.softamis.net.exchange.udp.UDPCommunicationHelper" ������� ��������init-method="init" destroy-method="close"> [4]� ������<property name="multicaster"> ������ ������<bean class="org.softamis.net.multicast.DefaultMulticaster" ��������� ��������init-method="start" destroy-method="close"> �� ������������<property name="groupName" value="230.0.0.10"/> ����� ���������<property name="timeToLive" value="5"/> ����������� <property name="port" value="1000"/> ��������� </bean> ������� </property> ����� </bean> ��� </property> [5] <property name="requestItemsOnInit" value="true"/> [6] <property name="defaultMessageSignature" value="EX"/> � </bean> Configuration comments:
Using specialized proxy factory beanThe listing below illustrates minimal configuration with specialized proxy factory bean that is used to implement dynamic one-to-may scheme of remoting. Please refer to configuration comments below to find more information on every particular element of declaration. [1]<bean name="TestService.compact.minimal" �� �������class="org.softamis.cluster4spring.rmi.RmiDiscoveringProxyFactoryBean"> [2]<property name="serviceInterface" �������������� value="org.softamis.cluster4spring.example.Service"/> [3]� <property name="serviceName" value="TestService"/> [4]� <property name="serviceGroup" value="DEFAULT"/> [5]� <propertyname="clientServicesRegistry" value="_ClientServicesRegistry"/> � </bean> Configuration comments:
Please note that it is not necessary to define one bean that represent client services registry for every declaration of remote service proxy. On the contrary, several remote service proxies may use the same instance of distributed services registry. Again, it is possible to configure all generic properties as it shown above. Using generic proxy factory beanIf, for some reasons, using generic exporter is more preferable, it is possible to use a different configuration (which is functionally equivalent to listing above) that utilizes generic exporter customized by specific EndpointProvider. The following listing illustrates such a configuration. Please refer to configuration comments below to find more information on every particular element of declaration. [1]<bean name="TestService.verbose.minimal" ����� class="org.softamis.cluster4spring.rmi.RmiProxyFactoryBean"> �� <property name="serviceInterface" value="org.softamis.cluster4spring.example.Service"/> �� <property name="endpointProvider"> [2] <bean class="org.softamis.cluster4spring.support.provider.DiscoveringEndpointProvider"> [3]�� <property name="serviceName" value="TestService"/> [4]�� <property name="serviceGroup" value="DEFAULT"/> [5]� �<property name="clientServicesRegistry" value="_ClientServicesRegistry"/> ��� </bean> �� </property> </bean> Configuration comments:
Server part of distributed services registryTo support one-to-many remoting scheme with dynamic services discovering, it is necessary to configure server part of distributed services registry. The following listing illustrates configuration for server part of distributed services registry. Please refer to configuration comments below to find more information for every particular element of declaration. [1] <bean name="ServerServicesRegistry" class="org.softamis.net.registry.spring.DefaultProvidingRegistry" init-method="init" ������� destroy-method="close">��� [2]��� <property name="communicationHelper"> [3]����� <bean class="org.softamis.net.exchange.udp.UDPCommunicationHelper" init-method="init" destroy-method="close"> [4]�������<property name="multicaster"> � �����������<bean class="org.softamis.net.multicast.DefaultMulticaster" ����������������� init-method="start" destroy-method="close"> ����������� ����<property name="groupName" value="230.0.0.10"/> ��� ������������<property name="timeToLive" value="5"/> ��� ������������<property name="port" value="1000"/> �� ����������</bean> �� �������</property> ���� ���</bean> �� ���</property> [5]��<property name="defaultMessageSignature" value="EX"/> � </bean> Configuration comments:
Configuring remote service exporterIf one-to-many remoting scheme with dynamic services discovering is used, it is necessary to use remote service exporter included into Cluster4Spring. The following listing illustrates server-side configuration for remote service exporter. Please refer to configuration comments below to find more information on every element of declaration. [1]<bean class="org.softamis.cluster4spring.rmi.RmiServiceExporter"> [2]�� <property name="allowsAutoDiscovering" value="true"/> [3] ��<property name="registry" ref="RMIRegistry"/> [4] ��<property name="service"> �������<bean class="org.softamis.cluster4spring.example.ServiceImpl"/> � ����</property> [5]�� <property name="serviceInterface" �������������� value="org.softamis.cluster4spring.example.Service"/> [6]� <property name="serviceName" value="TestService"/> � </bean> Configuration comments:
Please note that general properties that can be configured for service exporter were considered earlier and are not included into the listing above. Configuring remote services publisherIt is responsibility of ServicePublisher to collect information about exported remote services and store it in the distributed services registry. The following listing illustrates server-side configuration for ServicePublisher. Please refer to configuration comments below to get more information on every element of declaration. [1]<bean id="RMIServicesPublisher" class="org.softamis.cluster4spring.rmi.RmiServicePublisher"> [2]� <property name="servicesRegistry" ref="ServerServicesRegistry"/> [3]� <property name="cacheAutoDiscoveredServicesInfo" value="true"/> [4]� <propertyname="serverID"value="123"/> [5] �<property name="serviceGroup" value="DEFAULT"/> [6]� <property name="serverType"value="DEF"/> [7]� <property name="exporterAcceptor"> �� ����<bean class="org.softamis.cluster4spring.support.context.DefaultExporterAcceptor"/> �� ��</property> ��</bean> Configuration comments:
Of course, it is not necessary to declare one instance of ServicePublisher per instance of ServiceExporter. Instead of this, one ServicePublisher should be declared for one instance of distributed service registry. Generic configuration tipsThe examples above are correct, but since their main purpose was demonstrating options that could be configured, they are not optimal. This section of document contains some small tips that allow having optimal setup of remoting subsystem with the use of short-form configuration. In general, they are not specific to Cluster4Spring remoting and are quite general. The list of such tips is very short and contains just two major recommendations (funny, but they are applicable to configuring standard Spring remoting subsystem):
The following example illustrates the preferred way to define remoting related configuration assuming that client uses more than one remote service applied to configuration of one-to-one remoting (for simplicity's sake). Obviously, it will be even more effectively applied to other remoting schemes. [1]<bean name="_RmiEndpointFactory" class="org.softamis.cluster4spring.rmi.support.RmiEndpointFactory"/> ��<bean name="_RemoteInvocationFactory" class="org.springframework.support.DefaultRemoteInvocationFactory"/> [2]<bean name="REMOTE_SERVICE_CLIENT" ������� class="org.softamis.cluster4spring.rmi.RmiSingleUrlProxyFactoryBean" ������� abstract="true"> ��� <property name="refreshEndpointsOnConnectFailure" value="true"/> ��� <property name="refreshEndpointsOnStartup" value="true"/> ��� <property name="registerTraceInterceptor" value="true"/> ��� <property name="switchEndpointOnFailure" value="false"/> ��� <property name="interceptorNames" ������������value="_TestClientLoggingInterceptor, _TestClientEmptyInterceptor"/> ��� <property name="endpointFactory" ref="_RmiEndpointFactory"/> ��� <property name="remoteInvocationFactory" ref="_RemoteInvocationFactory"/> � </bean> [3] � <bean name="TestService1" parent="REMOTE_SERVICE_CLIENT"> ��� <property name="serviceInterface" ������������ value="org.softamis.cluster4spring.example.ServiceImpl"/> ��� <property name="serviceUrl" value="rmi://serverA:1099/TestService"/> � </bean> � <bean name="TestService2" parent="REMOTE_SERVICE_CLIENT"> ��� <property name="serviceInterface" ������������ value="org.softamis.cluster4spring.example.ServiceImpl"/> ��� <property name="serviceUrl" value="rmi://serverB:1099/TestService"/> � </bean> Configuration comments:
|
|