Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.infinispan.query.remote;
  
  import  com.google.protobuf.Descriptors;
  import  org.infinispan.commons.CacheException;
  import  org.infinispan.commons.marshall.AdvancedExternalizer;
 import  org.infinispan.protostream.ProtobufUtil;
 import  org.infinispan.protostream.SerializationContext;
 import  org.infinispan.query.remote.client.MarshallerRegistration;
 
 import java.util.Map;

Author(s):
anistor@redhat.com
Since:
6.0
 
 public class LifecycleManager extends AbstractModuleLifecycle {
 
    private static final Log log = LogFactory.getLog(LifecycleManager.classLog.class);
 
    private void initProtobufMetadataManager(DefaultCacheManager cacheManagerGlobalComponentRegistry gcr) {
       SerializationContext serCtx = ProtobufUtil.newSerializationContext();
       try {
          MarshallerRegistration.registerMarshallers(serCtx);
       } catch (IOException e) {
          throw new CacheException("Failed to initialise serialization context"e);
       } catch (Descriptors.DescriptorValidationException e) {
          throw new CacheException("Failed to initialise serialization context"e);
       }
 
       ProtobufMetadataManager protobufMetadataManager = new ProtobufMetadataManager(serCtx);
       gcr.registerComponent(protobufMetadataManagerProtobufMetadataManager.class);
 
       registerProtobufMetadataManagerMBean(protobufMetadataManagergcrcacheManager.getName());
    }
 
    @Override
    public void cacheManagerStarting(GlobalComponentRegistry gcrGlobalConfiguration globalCfg) {
       Map<Integer, AdvancedExternalizer<?>> externalizerMap = globalCfg.serialization().advancedExternalizers();
       externalizerMap.put(.new ProtobufValueWrapper.Externalizer());
    }
 
    @Override
    public void cacheManagerStarted(GlobalComponentRegistry gcr) {
       EmbeddedCacheManager cacheManager = gcr.getComponent(EmbeddedCacheManager.class);
       initProtobufMetadataManager((DefaultCacheManagercacheManagergcr);
    }
 
    private void registerProtobufMetadataManagerMBean(ProtobufMetadataManager protobufMetadataManagerGlobalComponentRegistry gcrString cacheManagerName) {
       GlobalConfiguration globalCfg = gcr.getGlobalConfiguration();
       MBeanServer mBeanServer = JmxUtil.lookupMBeanServer(globalCfg);
 
       String groupName = "type=RemoteQuery,name=" + ObjectName.quote(cacheManagerName);
       String jmxDomain = JmxUtil.buildJmxDomain(globalCfgmBeanServergroupName);
       ComponentMetadataRepo metadataRepo = gcr.getComponentMetadataRepo();
       ManageableComponentMetadata metadata = metadataRepo.findComponentMetadata(ProtobufMetadataManager.class)
             .toManageableComponentMetadata();
       try {
          ResourceDMBean mBean = new ResourceDMBean(protobufMetadataManagermetadata);
          ObjectName objName = new ObjectName(jmxDomain + ":" + groupName + ",component=" + metadata.getJmxObjectName());
          protobufMetadataManager.setObjectName(objName);
          JmxUtil.registerMBean(mBeanobjNamemBeanServer);
       } catch (Exception e) {
          throw new CacheException("Unable to register ProtobufMetadataManager MBean"e);
       }
    }
 
    @Override
    public void cacheManagerStopping(GlobalComponentRegistry gcr) {
    }
 
       try {
          ObjectName objName = gcr.getComponent(ProtobufMetadataManager.class).getObjectName();
         MBeanServer mBeanServer = JmxUtil.lookupMBeanServer(gcr.getGlobalConfiguration());
         JmxUtil.unregisterMBean(objNamemBeanServer);
      } catch (Exception e) {
         throw new CacheException("Unable to unregister ProtobufMetadataManager MBean"e);
      }
   }

   
Registers the remote value wrapper interceptor in the cache before it gets started.
   public void cacheStarting(ComponentRegistry crConfiguration cfgString cacheName) {
      if (cfg.indexing().enabled() && !cfg.compatibility().enabled()) {
         .infof("Registering RemoteValueWrapperInterceptor for cache %s"cacheName);
         createRemoteIndexingInterceptor(crcfg);
      }
   }
      RemoteValueWrapperInterceptor wrapperInterceptor = cr.getComponent(RemoteValueWrapperInterceptor.class);
      if (wrapperInterceptor == null) {
         wrapperInterceptor = new RemoteValueWrapperInterceptor();
         // Interceptor registration not needed, core configuration handling
         // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry!
         InterceptorChain ic = cr.getComponent(InterceptorChain.class);
         ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg);
         InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor();
         interceptorBuilder.interceptor(wrapperInterceptor);
         if (cfg.invocationBatching().enabled()) {
            if (ic != nullic.addInterceptorAfter(wrapperInterceptorBatchingInterceptor.class);
            interceptorBuilder.after(BatchingInterceptor.class);
         } else {
            if (ic != nullic.addInterceptorAfter(wrapperInterceptorInvocationContextInterceptor.class);
            interceptorBuilder.after(InvocationContextInterceptor.class);
         }
         if (ic != null) {
            cr.registerComponent(wrapperInterceptorRemoteValueWrapperInterceptor.class);
            cr.registerComponent(wrapperInterceptorwrapperInterceptor.getClass().getName(), true);
         }
      }
   }
   public void cacheStarted(ComponentRegistry crString cacheName) {
      Configuration configuration = cr.getComponent(Configuration.class);
      boolean removeValueWrappingEnabled = configuration.indexing().enabled() && !configuration.compatibility().enabled();
      if (!removeValueWrappingEnabled) {
            throw new IllegalStateException("It was NOT expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain as indexing was disabled, but it was found");
         }
         return;
      }
         throw new IllegalStateException("It was expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain but it wasn't found");
      }
   }
      InterceptorChain interceptorChain = cr.getComponent(InterceptorChain.class);
      return interceptorChain.containsInterceptorType(RemoteValueWrapperInterceptor.classtrue);
   }
   public void cacheStopped(ComponentRegistry crString cacheName) {
      Configuration cfg = cr.getComponent(Configuration.class);
   }
      ConfigurationBuilder builder = new ConfigurationBuilder();
      CustomInterceptorsConfigurationBuilder customInterceptorsBuilder = builder.customInterceptors();
      for (InterceptorConfiguration interceptorConfig : cfg.customInterceptors().interceptors()) {
         if (!(interceptorConfig.interceptor() instanceof RemoteValueWrapperInterceptor)) {
            customInterceptorsBuilder.addInterceptor().read(interceptorConfig);
         }
      }
   }
New to GrepCode? Check out our FAQ X