extensions/net.sf.basedb.varsearch/trunk/src/net/sf/basedb/varsearch/service/VarSearchServiceFactory.java

Code
Comments
Other
Rev Date Author Line
6111 29 Jan 21 nicklas 1 package net.sf.basedb.varsearch.service;
6111 29 Jan 21 nicklas 2
6111 29 Jan 21 nicklas 3 import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction;
6111 29 Jan 21 nicklas 4 import net.sf.basedb.core.SessionControl;
6111 29 Jan 21 nicklas 5 import net.sf.basedb.util.extensions.ActionFactory;
6111 29 Jan 21 nicklas 6 import net.sf.basedb.util.extensions.Extension;
6111 29 Jan 21 nicklas 7 import net.sf.basedb.util.extensions.InvokationContext;
6111 29 Jan 21 nicklas 8
6111 29 Jan 21 nicklas 9 /**
6111 29 Jan 21 nicklas 10   Action factory and service controller for the {@link VarSearchService}. 
6111 29 Jan 21 nicklas 11   This hooks into the BASE web client's "services" extension point making
6111 29 Jan 21 nicklas 12   it possible to start and stop the service from the web interface.
6111 29 Jan 21 nicklas 13   Do not use this class from other extensions.
6111 29 Jan 21 nicklas 14
6111 29 Jan 21 nicklas 15   @author nicklas
6111 29 Jan 21 nicklas 16   @since 1.0
6111 29 Jan 21 nicklas 17 */
6111 29 Jan 21 nicklas 18 public class VarSearchServiceFactory 
6111 29 Jan 21 nicklas 19   implements ActionFactory<ServiceControllerAction>
6111 29 Jan 21 nicklas 20 {
6111 29 Jan 21 nicklas 21
6111 29 Jan 21 nicklas 22   
6111 29 Jan 21 nicklas 23   public VarSearchServiceFactory()
6111 29 Jan 21 nicklas 24   {}
6111 29 Jan 21 nicklas 25   
6111 29 Jan 21 nicklas 26   /*
6111 29 Jan 21 nicklas 27     From the ActionFactory interface
6111 29 Jan 21 nicklas 28     --------------------------------
6111 29 Jan 21 nicklas 29   */
6111 29 Jan 21 nicklas 30   @Override
6111 29 Jan 21 nicklas 31   public boolean prepareContext(InvokationContext<? super ServiceControllerAction> context) 
6111 29 Jan 21 nicklas 32   {
6111 29 Jan 21 nicklas 33     return true;
6111 29 Jan 21 nicklas 34   }
6111 29 Jan 21 nicklas 35
6111 29 Jan 21 nicklas 36   @Override
6111 29 Jan 21 nicklas 37   public ServiceControllerAction[] getActions(InvokationContext<? super ServiceControllerAction> context)
6111 29 Jan 21 nicklas 38   {
6111 29 Jan 21 nicklas 39     SessionControl sc = context.getClientContext().getSessionControl();
6111 29 Jan 21 nicklas 40     return new ServiceControllerAction[] { new VarSearchServiceControllerAction(sc, context.getExtension()) };
6111 29 Jan 21 nicklas 41   }
6111 29 Jan 21 nicklas 42   // ---------------------------------------------
6111 29 Jan 21 nicklas 43
6111 29 Jan 21 nicklas 44   static class VarSearchServiceControllerAction
6111 29 Jan 21 nicklas 45     implements ServiceControllerAction
6111 29 Jan 21 nicklas 46   {
6111 29 Jan 21 nicklas 47     private final SessionControl sc;
6111 29 Jan 21 nicklas 48     private final Extension<ServiceControllerAction> ext;
6111 29 Jan 21 nicklas 49     
6111 29 Jan 21 nicklas 50     @SuppressWarnings({ "unchecked", "rawtypes" })
6111 29 Jan 21 nicklas 51     VarSearchServiceControllerAction(SessionControl sc, Extension ext)
6111 29 Jan 21 nicklas 52     {
6111 29 Jan 21 nicklas 53       this.sc = sc;
6111 29 Jan 21 nicklas 54       this.ext = (Extension<ServiceControllerAction>)ext;
6111 29 Jan 21 nicklas 55     }
6111 29 Jan 21 nicklas 56     
6111 29 Jan 21 nicklas 57     /*
6111 29 Jan 21 nicklas 58       From the ServiceControllerAction interface
6111 29 Jan 21 nicklas 59       ------------------------------------------
6111 29 Jan 21 nicklas 60     */
6111 29 Jan 21 nicklas 61     @Override
6111 29 Jan 21 nicklas 62     public boolean isRunning()
6111 29 Jan 21 nicklas 63     {
6111 29 Jan 21 nicklas 64       return VarSearchService.getInstance().isRunning();
6111 29 Jan 21 nicklas 65     }
6111 29 Jan 21 nicklas 66   
6111 29 Jan 21 nicklas 67     @Override
6111 29 Jan 21 nicklas 68     public void start() 
6111 29 Jan 21 nicklas 69     {
6111 29 Jan 21 nicklas 70       VarSearchService.getInstance().start(sc, ext);
6111 29 Jan 21 nicklas 71     }
6111 29 Jan 21 nicklas 72   
6111 29 Jan 21 nicklas 73     @Override
6111 29 Jan 21 nicklas 74     public void stop() 
6111 29 Jan 21 nicklas 75     {
6111 29 Jan 21 nicklas 76       VarSearchService.getInstance().stop();
6111 29 Jan 21 nicklas 77     }
6111 29 Jan 21 nicklas 78     // --------------------------------------
6111 29 Jan 21 nicklas 79   
6111 29 Jan 21 nicklas 80     @Override
6111 29 Jan 21 nicklas 81     public String toString() 
6111 29 Jan 21 nicklas 82     {
6111 29 Jan 21 nicklas 83       return "Variant Indexing Service";
6111 29 Jan 21 nicklas 84     }
6111 29 Jan 21 nicklas 85   }
6111 29 Jan 21 nicklas 86
6111 29 Jan 21 nicklas 87 }