Use MongoDB

If your application uses an important set of values, you can choose to store them in MongoDB  :

  • create a database: use databaseName;
  • create a user on it: db.createUser({user :  "username" ,pwd : "password",roles :["readWrite"]}) ;

In the System Parameters, modify MongoHost, MongoPort, MongoDatabase, MongoUser and MongoPassword
Capturedecran2015-06-04a15.45.54.png

You have now to create a java class in order to make your bundle to listen to the service TimeSerieMongoClientService. In the pom file’s directory of your bundle execute following command:

  • mvm clean install
  • mvn eclipse:eclipse

Then import the bundle as an eclipse project to add that class which activate the service :
Right click -> Import -> General -> existing project into workspace and specify the folder of your bundle in tomcat/dysoweb.home/application
Capturedecran2015-06-04a16.13.56.png

Create a class Activator in the folder src/main/java:

public class Activator implements BundleActivator {

private BundleContext fContext;
private IApplicationService fApplicationService;
private static Activator fInstance;
private ITimeSeriesMongoClientService fMongoService;

public Activator() {
 
}

public void start(BundleContext context) throws Exception {
  fContext = context;
  registerApplicationServiceListener(context);
  registerMongoServiceListener(context);
  fInstance = this;
}

public void stop(BundleContext context) throws Exception {
  fContext = null;
  fInstance = null;
}

public static Activator getDefault() {
 return fInstance;
}

public IApplicationService getApplicationService() {
 // retrieve the import service for the running instance
 return fApplicationService;
}

private void registerApplicationServiceListener(BundleContext context) throws InvalidSyntaxException {
 // get the service ref if the auth plugin is already started
 ServiceReference sr = context.getServiceReference(IApplicationService.class.getName());
 if(sr != null) {
   fApplicationService = (IApplicationService)context.getService(sr);
 }
 
  ServiceListener sl = new ServiceListener() {

  @Override
  public void serviceChanged(ServiceEvent ev) {
    ServiceReference sr = ev.getServiceReference();
   switch (ev.getType()) {
    case ServiceEvent.REGISTERED: {
      fApplicationService = (IApplicationService)fContext.getService(sr);
    }
    break;
    case ServiceEvent.UNREGISTERING: {
      fApplicationService = null;
    }
    break;
   }
  }
 };

  String filter = "(objectclass="
   + IApplicationService.class.getName() + ")";
  context.addServiceListener(sl, filter);
}

private void registerMongoServiceListener(BundleContext context) throws InvalidSyntaxException {
    // get the service ref if the auth plugin is already started
    ServiceReference sr = context.getServiceReference(ITimeSeriesMongoClientService.class.getName());
    if(sr != null) {
         fMongoService = (ITimeSeriesMongoClientService)context.getService(sr);
    }

     ServiceListener sl = new ServiceListener() {

        @Override
        public void serviceChanged(ServiceEvent ev) {
             ServiceReference sr = ev.getServiceReference();
            switch (ev.getType()) {
                case ServiceEvent.REGISTERED: {
                     fMongoService = (ITimeSeriesMongoClientService)fContext.getService(sr);
                }
                break;
                case ServiceEvent.UNREGISTERING: {
                     fMongoService = null;
                }
                break;
            }
        }
    };

     String filter = "(objectclass="
            + ITimeSeriesMongoClientService.class.getName() + ")";
     context.addServiceListener(sl, filter);
}

public ITimeSeriesMongoClientService getMongoService() {
    return this.fMongoService;
}
}

To solve import errors, edit the pom.xml file:

  • add a dependency:
       <dependency>
           <groupId>com.requea.dynapage</groupId>
           <artifactId>com.requea.dynapage.mongo</artifactId>
           <scope>provided</scope>
           <version>4.0.245</version>
       </dependency>
  • add an import package:

com.requea.dynapage.mongo,

  • add a field bundle-activator after Import-Package mark:
<Bundle-Activator>com.requea.schneider.dlvm.Activator</Bundle-Activator>

Under src/main/META-INF, edit MANIFEST.MF:

  • add com.requea.dynapage.mongo in the section Import-Package
  • add the section Bundle-Activator: com.requea.name.Activator

Recompile the bundle with the command line mvm eclipse:eclipse

You can now add your bundle by  typing that command in the shell platform (under http://localhost:8080/dysoweb/dysoweb/panel/secure/shell.jsp):

start reference:file: /path to the bundle com.requea.name/src/main

If you change the version of Mongo and get an authentication error, you have to delete and recreate the folder /data/db

Tags:
Created by Pierre Dubois on 2015/06/11 10:51
     
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 9.11.5 - Documentation