コード例 #1
0
ファイル: ServiceManager.java プロジェクト: talip/hazelcast
 private void initService(
     Map<String, Properties> serviceProps,
     Map<String, Object> serviceConfigObjects,
     ServiceInfo serviceInfo) {
   final Object service = serviceInfo.getService();
   if (serviceInfo.isConfigurableService()) {
     try {
       if (logger.isFinestEnabled()) {
         logger.finest("Configuring service -> " + service);
       }
       final Object configObject = serviceConfigObjects.get(serviceInfo.getName());
       ((ConfigurableService) service).configure(configObject);
     } catch (Throwable t) {
       logger.severe("Error while configuring service: " + t.getMessage(), t);
     }
   }
   if (serviceInfo.isManagedService()) {
     try {
       if (logger.isFinestEnabled()) {
         logger.finest("Initializing service -> " + service);
       }
       final Properties props = serviceProps.get(serviceInfo.getName());
       ((ManagedService) service).init(nodeEngine, props != null ? props : new Properties());
     } catch (Throwable t) {
       logger.severe("Error while initializing service: " + t.getMessage(), t);
     }
   }
 }
コード例 #2
0
ファイル: ServiceManager.java プロジェクト: talip/hazelcast
 /**
  * Returns a list of services matching provided service class/interface. <br>
  * </br> <b>CoreServices will be placed at the beginning of the list.</b>
  */
 List<ServiceInfo> getServiceInfos(Class serviceClass) {
   final LinkedList<ServiceInfo> result = new LinkedList<ServiceInfo>();
   for (ServiceInfo serviceInfo : services.values()) {
     if (serviceInfo.isInstanceOf(serviceClass)) {
       if (serviceInfo.isCoreService()) {
         result.addFirst(serviceInfo);
       } else {
         result.addLast(serviceInfo);
       }
     }
   }
   return result;
 }
コード例 #3
0
 private Collection<Operation> prepareMigrationTasks() {
   NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
   final PartitionReplicationEvent replicationEvent =
       new PartitionReplicationEvent(migrationInfo.getPartitionId(), 0);
   final PartitionMigrationEvent migrationEvent =
       new PartitionMigrationEvent(MigrationEndpoint.SOURCE, migrationInfo.getPartitionId());
   final Collection<Operation> tasks = new LinkedList<Operation>();
   for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(MigrationAwareService.class)) {
     MigrationAwareService service = (MigrationAwareService) serviceInfo.getService();
     service.beforeMigration(migrationEvent);
     final Operation op = service.prepareReplicationOperation(replicationEvent);
     if (op != null) {
       op.setServiceName(serviceInfo.getName());
       tasks.add(op);
     }
   }
   return tasks;
 }
コード例 #4
0
ファイル: ServiceManager.java プロジェクト: talip/hazelcast
 private synchronized void registerService(String serviceName, Object service) {
   if (logger.isFinestEnabled()) {
     logger.finest("Registering service: '" + serviceName + "'");
   }
   final ServiceInfo serviceInfo = new ServiceInfo(serviceName, service);
   final ServiceInfo currentServiceInfo = services.putIfAbsent(serviceName, serviceInfo);
   if (currentServiceInfo != null) {
     logger.warning("Replacing " + currentServiceInfo + " with " + serviceInfo);
     if (currentServiceInfo.isCoreService()) {
       throw new HazelcastException(
           "Can not replace a CoreService! Name: "
               + serviceName
               + ", Service: "
               + currentServiceInfo.getService());
     }
     if (currentServiceInfo.isManagedService()) {
       shutdownService((ManagedService) currentServiceInfo.getService(), false);
     }
     services.put(serviceName, serviceInfo);
   }
 }