SessionDistributorService

SessionDistributorService - distributed service localted in ano-prise project, net.anotheria.anoprise.sessiondistributor.SessionDistributorService.
Main goal of current service - centralized storage for APISessionDistribution.

1. How to use in projects. Main steps.

SessionDistributorService - is not annotated by distributeMe annotations, but SessionDistributorService should be distributed. Let's see how to deal with it.

How to deal with default implementation on back-end

step1 : create some Your own SessionDistributionService interface in Your custom project which will extends net.anotheria.anoprise.sessiondistributor.SessionDistributorService;
step2 : annotate Your SessionDistributionService with @DistributeME annotation;

 

package net.myservice.sessiondistributor;
/**
* This is custom SessionDistributorService, as example.
*/
@DistributeMe(factoryClazz = MySessionDistributorServiceFactory.class)
public interface MySessionDistributorService extends net.anotheria.anoprise.sessiondistributor.SessionDistributorService {
}

step3 : Create implementation and factory for Your SessionDistributorService ;

package net.myservice.sessiondistributor;
/**
* This is custom SessionDistributorService implementation, as example.
*/
public class MySessionDistributorServiceImpl extends net.anotheria.anoprise.sessiondistributor.SessionDistributorServiceImpl implements MySessionDistributorService {
}
package net.myservice.sessiondistributor;

/**
* This is custom SessionDistributorService factory, as example.
*/
public class MySessionDistributorServiceFactory implements ServiceFactory<MySessionDistributorService> {

	@Override
	public SessionDistributorBusinessService create() {
		return new MySessionDistributorServiceImpl();
	}
}

After this 3 steps are finished, simply run DistributeME - generate task, and You will receive all required classes ( stub, skeleton, server .....)

 

For ano-prise 1.0.24

Clustering options are available! 

 - Starting 1.0.24 release SessionDistributorService supporst Clusterring. Add RouteMe, Route and FailBy anotations to Youre custom  SessionDistributor interface extension....

 

@RouteMe(providerClass = PropertyBasedRegistrationNameProvider.class, providerParameter = "extension")  - allow to start few SessionDistributorService with different ids,  simply path "-Dextension=" to server start script   (start from 0).

@Route(routerClass = SessionDistributorServiceMethodCallsRouter.class, routerParameter = "") – enables Routing between different SDService instances;

@FailBy(strategyClass = SessionDistributorServiceMethodCallsRouter.class) - enables fail-Over feature;

 

 

 

 

 

 

How to deal with default implementation on front-end

To integrate just completed examples from "How to deal with default implementation on back-end" simply follow next instructions:

step 1 : check, that APISessionDistribution is enabled in "ano-plass-api-session-distribution" - refer to APISession configuration section;

step 2 : in ContextInitializer (ServletContextListener) of Your web application add next init code line

// This is MetaFactory based example, but You can use any DI engine which You like.....
    APISessionDistributionHelper.setSessionDistributorService(MetaFactory.get(MySessionDistributorService.class));

After steps completed, run first run distributed MySessionDistributorServer, which located in net.myservice.sessiondistributor.generated package. Then deploy Your web app.
Enjoy (smile)

2. SessionDistributorService configuration.

net.anotheria.anoprise.sessiondistributor.SessionDistributorServiceConfig - provides configuration options for SessionDistributorService.
Actually this is configuration class based on ConfigureME configuration utility.

SessionDistributorServiceConfig read configuration from "ano-prise-session-distributor-service.json" file.

Options which can be configured

distributedSessionsCleanUpInterval - represent time interval after which distributed sessions clean-UP task will check and remove outdated distributed sessions;

distributedSessionMaxAge - represent distributed session max age (on each call to Distributed and also on Keep-alive calls - "lastChangeTime" property of distributed session set to current-time);

sessionDistributorEventQueueSize - this is event channel queue size for SessioDistributorService;

sessionDistributorEventQueueSleepTime - this is event channel queue sleep time for SessioDistributorService.


for 1.0.24 and higher

multipleInstancesEnabled - enable/disable SessionDistributorService-clustering...

sessionDistributorServersAmount - amount of SD nodes insinde SD cluster ( actually configuration for SessionDistributorServiceMethodCallsRouter).

failingStrategyEnabled - enable / disable failing for SessionDistributorServiceMethodCallsRouter.

wrightSessionsToFsOnShutdownEnabled - enable / disable SDCache persistence to FS on ShutdownHook.

sdSessionsFSRootFolder - ROOT folder fom SDCache persistence.

sdSessionsFileExtension - extension for SDCache file - which was persisted to FS.

sdCacheEventQueueSize - event channel size SDCache.

sdCacheEventQueueSleepTime - event channel sleep time for SDCache.


starting from 1.0.26

 nodeIdSystemPropertyName  - configurable property under which cluster node ID can be passed as SystemProperty to any cluster node!    "extension" used by defaults

 in case when fall dows to fs  will be enabled  - file with cache content will be named as this ID. etc

For ano-prise 1.1.0

 maxSessionsCount  - configurable property which defines  amount of distributed session ( in cluster mode - amount stay SAME)   - 1000 is default value.

sessionsLimitEnabled  - configurable property which allow turn off and on - Distributed session amount LIMIT.

 

 

 

 

 

 

Default values

If config file "ano-prise-session-distributor-service.json" not present, then next default values will be used :

distributedSessionsCleanUpInterval = TimeUnit.MINUTE.getMillis() * 5;// five minutes
distributedSessionMaxAge = TimeUnit.MINUTE.getMillis() * 10; //ten minutes
sessionDistributorEventQueueSize = 5000;
sessionDistributorEventQueueSleepTime = 300; // 300 ms

NEXT configuration attributes added in ano-prise 1.0.24 version!!!

multipleInstancesEnabled =false; //disabled by default
sessionDistributorServersAmount = 1; // 1 node by default, cause clustering is disabled
failingStrategyEnabled = false; // failing disabled
wrightSessionsToFsOnShutdownEnabled = false; // sessions persistence on SHUTDOWN disabled
sdSessionsFSRootFolder = "sessionDistributorService_sessionsState"; //persist to ./sessionDistributorService_sessionsState folder
sdSessionsFileExtension = "sds"; //.sds file extension will be used
sdCacheEventQueueSize = 5000;
sdCacheEventQueueSleepTime = 300; // 300 ms
nodeIdSystemPropertyName = "extension"; 


Starting from 1.1.0  - in Context of https://jira.opensource.anotheria.net/browse/ANOPRISE-11 next properties added!

maxSessionsCount = 1000; //Global sessions amount LIMIT
sessionsLimitEnabled = false; // Allows to turn off and On sessions count limit!

3. SessionDistributorService interface methods, and implementation details.

In current SessionDistributorService there are 9 methods :

createDistributedSession

Method used for distributed session create. It takes string sessionId as incoming parameter. This parameter is possible id of distributed session which is proposed by caller - APISessionManager. If distributed session with such id does not exists, then this proposed id will be used, otherwise id will be generated inside create method.

deleteDistributedSession

Method deletes distributed session, and takes id of session to delete as incoming parameter. If no session with such id exist, SessionDistributorServiceException will be thrown. Method generates
net.anotheria.anoprise.sessiondistributor.events.SessionDeleteEvent in default implementation.

restoreDistributedSession

Method return to caller APISessionManager distributed session with selected id. It operates with 2 incoming parameters: "name - distributed session id", and "callerId - id of APISessionManager which call restore".
If no session with such id exist, SessionDistributorServiceException will be thrown. Method generates net.anotheria.anoprise.sessiondistributor.events.SessionRestoreEvent.

getDistributedSessionNames

Simplest method, which return Collection of distributed session Id's.

updateSessionUserId

Method update userId property of distributed session with selected id. Operates with 2 incoming parameters: "name - distributed session id", and "userId - id of user". If no session with such id exist, SessionDistributorServiceException will be thrown.

updateSessionEditorId

Method update userId property of distributed session with selected id. Operates with 2 incoming parameters: "name - distributed session id", and "editorId - id of editor". If no session with such id exist, SessionDistributorServiceException will be thrown.

addDistributedAttribute

Method add or update net.anotheria.anoprise.sessiondistributor.DistributedSessionAttribute to distributed session. Operates with 2 incoming parameters : "name - distributed session id", "attribute - attribute to add/update". If no session with such id exist, SessionDistributorServiceException will be thrown.

removeDistributedAttribute

Method remove distributed attribute from distributed session. Operates with 2 incoming parameters : "name - distributed session id", "attributeName - name of attribute to remove". If no session with such id exist, SessionDistributorServiceException will be thrown.

keepDistributedSessionAlive

Method prolongs distributed session expiration time. Operates with 1 incoming parameter : "name - distributed session id". If no session with such id exist, SessionDistributorServiceException will be thrown.

4. Events.

SessionDistributorService generates next events :

  1. net.anotheria.anoprise.sessiondistributor.events.SessionRestoreEvent - contains restored session id, and caller - which is  APISessionManager  id;
  2. net.anotheria.anoprise.sessiondistributor.events.SessionDeleteEvent - contains deleted session id;
  3. net.anotheria.anoprise.sessiondistributor.events.SessionCleanUpEvent - contains Collection of outdated session ids.

All required Constants and login can be found under net.anotheria.anoprise.sessiondistributor.events package.

 

5. Clustering of SessionDistributorService.

Starting from ano-prise 1.0.24 SDService supports clustering. Clustering is configurable feature which is configurable via ServiceConfiguration

SessionDistributorServiceMethodCallsRouter.

 Class used  for call-routing  between different cluster nodes. Supports Fail-Over. Use next annotations  :

@RouteMe(providerClass = PropertyBasedRegistrationNameProvider.class, providerParameter = "extension")
@Route(routerClass = SessionDistributorServiceMethodCallsRouter.class, routerParameter = "")
@FailBy(strategyClass = SessionDistributorServiceMethodCallsRouter.class)
@DistributeMe(factoryClazz = MySessionDistributorServiceFactory.class)
public interface MySessionDistributorService extends net.anotheria.anoprise.sessiondistributor.SessionDistributorService {
} 

  Router does not required any customization parameters cause they will be extracted from configuration file in RUNTIME!

 -- FROM service configuration section --
sessionDistributorServersAmount - Amount of nodes between which routing should be provided failingStrategyEnabled - Disabling and enabling failOver for Service

Max number of failOver tries

NOTE - max number of tries to prevent error - is  equal to configured servers amont  (sessionDistributorServersAmount - inside config)

Starting SD cluster.

 To run clasterable : 

 1 . Configuration check 

     - property  multipleInstancesEnabled  set to true (if FailOver required also set failingStrategyEnabled to true);

     - property sessionDistributorServersAmount value is more that 1;

     - property sdCacheEventQueueSize && sdCacheEventQueueSleepTime are more then 0 (but can be  default values  — sdCacheEventQueueSize=5000, sdCacheEventQueueSleepTime=300) etc;

also

If wrightSessionsToFsOnShutdownEnabled is enabled - ensure that sdSessionsFSRootFolder  && sdSessionsFileExtension are not blank!!!

 

2 . Depends on @RouteMe annotation providerParameter value - start running Youre  custom SessionDistributorServer —  pathing "-Dextension=" (extension - for this example —  that depends on anotation) value - starting from 0 and ending with sessionDistributorServersAmount-1 (sessionDistributorServersAmount from configutation).

 

also

Please note! - that  proper replication inside cluster will work only  then - when each cluster node will receive proper unique nodeId. Check that "nodeIdSystemPropertyName" - properly configured and passed to each on the  server start!

Best of all  simply configure "nodeIdSystemPropertyName"  with same value as @RouteMe annotation providerParameter ( "extension" from step 2) and then all will works as expected.......

 

 

 

 

 

6. Where to find ( which version to use).

ano-prise version

SessionDistirubtorService described above (in such implementation, with events, etc) can be found under version 1.0.19 or higher. So use next dependency :

Maven dependency for ano-prise

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-prise</artifactId>
<version>1.0.19</version>
</dependency>

 

-- Use 1.0.24 for more features (Clustering (built in Routing with Failing, async cache-update events. cache persistence on server shutDown, etc)) --

<dependency>

<groupId>net.anotheria</groupId>

<artifactId>ano-prise</artifactId>

<version>1.0.24</version>

</dependency>

 

Additional dependencies

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-prise</artifactId>
<version>1.0.26</version>
<classifier>sources</classifier>
</dependency>

 

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-prise</artifactId>
<version>1.0.26</version>
<classifier>javadoc</classifier>
</dependency>

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-prise</artifactId>
<version>1.0.26</version>
<classifier>sources</classifier>
</dependency>

ano-plass version (ano-plass as main client)

Related changes to ano-plass was published to version 1.0.4 or higher. Change Log (ano-plass)

 

Maven dependency for ano-plass

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-plass</artifactId>
<version>1.0.9</version>
</dependency>

Additional dependencies

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-plass</artifactId>
<version>1.0.9</version>
<classifier>javadoc</classifier>
</dependency>

<dependency>
<groupId>net.anotheria</groupId>
<artifactId>ano-plass</artifactId>
<version>1.0.9</version>
<classifier>sources</classifier>
</dependency>

Enjoy (smile)

  • No labels