Esempio n. 1
0
 @Override
 public CompletableFuture<Object> invokeAsync() throws Throwable {
   GlobalComponentRegistry globalComponentRegistry = cacheManager.getGlobalComponentRegistry();
   ComponentRegistry cacheComponentRegistry =
       globalComponentRegistry.getNamedComponentRegistry(cacheName);
   String name = cacheName.toString();
   if (cacheComponentRegistry != null) {
     cacheComponentRegistry.getComponent(PersistenceManager.class).setClearOnStop(true);
     cacheComponentRegistry.getComponent(CacheJmxRegistration.class).setUnregisterCacheMBean(true);
     cacheComponentRegistry.getComponent(PassivationManager.class).skipPassivationOnStop(true);
     Cache<?, ?> cache = cacheManager.getCache(name, false);
     if (cache != null) {
       cache.stop();
     }
   }
   globalComponentRegistry.removeCache(name);
   // Remove cache configuration and remove it from the computed cache name list
   globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
   // Remove cache from dependency graph
   //noinspection unchecked
   globalComponentRegistry
       .getComponent(DependencyGraph.class, CACHE_DEPENDENCY_GRAPH)
       .remove(cacheName);
   return CompletableFutures.completedNull();
 }
Esempio n. 2
0
 private void unregisterProtobufMetadataManagerMBean(GlobalComponentRegistry gcr) {
   try {
     ObjectName objName = gcr.getComponent(ProtobufMetadataManager.class).getObjectName();
     MBeanServer mBeanServer = JmxUtil.lookupMBeanServer(gcr.getGlobalConfiguration());
     JmxUtil.unregisterMBean(objName, mBeanServer);
   } catch (Exception e) {
     throw new CacheException("Unable to unregister ProtobufMetadataManager MBean", e);
   }
 }
 @Override
 protected EmbeddedCacheManager createCacheManager() throws Exception {
   ConfigurationBuilder c = getDefaultStandaloneCacheConfig(false);
   c.jmxStatistics().enable();
   cacheManager = TestCacheManagerFactory.createCacheManager(c);
   memcachedServer = MemcachedTestingUtil.startMemcachedTextServer(cacheManager);
   port = memcachedServer.getPort();
   memcachedClient = MemcachedTestingUtil.createMemcachedClient(60000, port);
   GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cacheManager);
   interpreter = gcr.getComponent(Interpreter.class);
   return cacheManager;
 }
 @Override
 protected void setup() throws Exception {
   super.setup();
   hotrodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager);
   port = hotrodServer.getPort();
   remoteCacheManager =
       new RemoteCacheManager(
           new org.infinispan.client.hotrod.configuration.ConfigurationBuilder()
               .addServers("localhost:" + hotrodServer.getPort())
               .build());
   remoteCacheManager.start();
   GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cacheManager);
   interpreter = gcr.getComponent(Interpreter.class);
 }
 /**
  * Replaces a component in a running cache manager (global component registry)
  *
  * @param cacheContainer cache in which to replace component
  * @param componentType component type of which to replace
  * @param replacementComponent new instance
  * @param rewire if true, ComponentRegistry.rewire() is called after replacing.
  * @return the original component that was replaced
  */
 public static <T> T replaceComponent(
     CacheContainer cacheContainer,
     Class<T> componentType,
     T replacementComponent,
     boolean rewire) {
   GlobalComponentRegistry cr = extractGlobalComponentRegistry(cacheContainer);
   T old = cr.getComponent(componentType);
   cr.registerComponent(replacementComponent, componentType);
   if (rewire) {
     cr.rewire();
     cr.rewireNamedRegistries();
   }
   return old;
 }
 protected static GMUVersionGenerator getGMUVersionGenerator(
     GlobalComponentRegistry globalComponentRegistry, String cacheName) {
   ComponentRegistry componentRegistry =
       globalComponentRegistry.getNamedComponentRegistry(cacheName);
   VersionGenerator versionGenerator = componentRegistry.getComponent(VersionGenerator.class);
   return toGMUVersionGenerator(versionGenerator);
 }
Esempio n. 7
0
 @Start(priority = 7) // Should start before global marshaller
 public void start() {
   loadInternalMarshallables();
   loadForeignMarshallables(gcr.getGlobalConfiguration());
   started = true;
   if (log.isTraceEnabled()) {
     log.tracef(
         "Constant object table was started and contains these externalizer readers: %s", readers);
     log.tracef("The externalizer writers collection contains: %s", writers);
   }
 }
  @Override
  public Object perform(InvocationContext ctx) throws Throwable {
    // To avoid reliance of a thread local flag, get a reference for the
    // cache store to be able to clear it after cache has stopped.
    CacheStore store = cacheLoaderManager.getCacheStore();
    cacheManager.getCache(cacheName).stop();

    // After stopping the cache, clear it
    if (store != null) store.clear();

    registry.removeCache(cacheName);
    return null;
  }
Esempio n. 9
0
 private SearchFactoryIntegrator getSearchFactory(
     Properties indexingProperties, ComponentRegistry cr) {
   Object component = cr.getComponent(SearchFactoryIntegrator.class);
   SearchFactoryIntegrator searchFactory = null;
   if (component
       instanceof
       SearchFactoryIntegrator) { // could be the placeholder Object REMOVED_REGISTRY_COMPONENT
     searchFactory = (SearchFactoryIntegrator) component;
   }
   // defend against multiple initialization:
   if (searchFactory == null) {
     GlobalComponentRegistry globalComponentRegistry = cr.getGlobalComponentRegistry();
     EmbeddedCacheManager uninitializedCacheManager =
         globalComponentRegistry.getComponent(EmbeddedCacheManager.class);
     indexingProperties = addProgrammaticMappings(indexingProperties, cr);
     // Set up the search factory for Hibernate Search first.
     SearchConfiguration config =
         new SearchableCacheConfiguration(
             new Class[0], indexingProperties, uninitializedCacheManager, cr);
     searchFactory = new SearchFactoryBuilder().configuration(config).buildSearchFactory();
     cr.registerComponent(searchFactory, SearchFactoryIntegrator.class);
   }
   return searchFactory;
 }
Esempio n. 10
0
  private void registerProtobufMetadataManagerMBean(
      ProtobufMetadataManager protobufMetadataManager,
      GlobalComponentRegistry gcr,
      String cacheManagerName) {
    GlobalConfiguration globalCfg = gcr.getGlobalConfiguration();
    MBeanServer mBeanServer = JmxUtil.lookupMBeanServer(globalCfg);

    String groupName = "type=RemoteQuery,name=" + ObjectName.quote(cacheManagerName);
    String jmxDomain = JmxUtil.buildJmxDomain(globalCfg, mBeanServer, groupName);
    ComponentMetadataRepo metadataRepo = gcr.getComponentMetadataRepo();
    ManageableComponentMetadata metadata =
        metadataRepo
            .findComponentMetadata(ProtobufMetadataManagerImpl.class)
            .toManageableComponentMetadata();
    try {
      ResourceDMBean mBean = new ResourceDMBean(protobufMetadataManager, metadata);
      ObjectName objName =
          new ObjectName(jmxDomain + ":" + groupName + ",component=" + metadata.getJmxObjectName());
      protobufMetadataManager.setObjectName(objName);
      JmxUtil.registerMBean(mBean, objName, mBeanServer);
    } catch (Exception e) {
      throw new CacheException("Unable to register ProtobufMetadataManager MBean", e);
    }
  }
Esempio n. 11
0
  @Override
  public Object readObject(Unmarshaller input) throws IOException, ClassNotFoundException {
    int readerIndex = input.readUnsignedByte();
    int foreignId = -1;
    if (readerIndex == Ids.MAX_ID) {
      // User defined externalizer
      foreignId = UnsignedNumeric.readUnsignedInt(input);
      readerIndex = generateForeignReaderIndex(foreignId);
    }

    ExternalizerAdapter adapter = readers.get(readerIndex);
    if (adapter == null) {
      if (!started) {
        log.tracef(
            "Either the marshaller has stopped or hasn't started. Read externalizers are not properly populated: %s",
            readers);

        if (Thread.currentThread().isInterrupted()) {
          throw log.pushReadInterruptionDueToCacheManagerShutdown(
              readerIndex, new InterruptedException());
        } else {
          throw log.cannotResolveExternalizerReader(gcr.getStatus(), readerIndex);
        }
      } else {
        if (log.isTraceEnabled()) {
          log.tracef("Unknown type. Input stream has %s to read", input.available());
          log.tracef("Check contents of read externalizers: %s", readers);
        }

        if (foreignId > 0) throw log.missingForeignExternalizer(foreignId);

        throw log.unknownExternalizerReaderIndex(readerIndex);
      }
    }

    return adapter.readObject(input);
  }
Esempio n. 12
0
 @Override
 public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalCfg) {
   metadataRepo = gcr.getComponentMetadataRepo();
 }
Esempio n. 13
0
 @Override
 public void cacheManagerStarted(GlobalComponentRegistry gcr) {
   EmbeddedCacheManager cacheManager = gcr.getComponent(EmbeddedCacheManager.class);
   initProtobufMetadataManager((DefaultCacheManager) cacheManager, gcr);
 }
 public static ExternalizerTable extractExtTable(CacheContainer cacheContainer) {
   GlobalComponentRegistry gcr =
       (GlobalComponentRegistry) extractField(cacheContainer, "globalComponentRegistry");
   return gcr.getComponent(ExternalizerTable.class);
 }
 public static AbstractDelegatingMarshaller extractGlobalMarshaller(EmbeddedCacheManager cm) {
   GlobalComponentRegistry gcr =
       (GlobalComponentRegistry) extractField(cm, "globalComponentRegistry");
   return (AbstractDelegatingMarshaller)
       gcr.getComponent(StreamingMarshaller.class, KnownComponentNames.GLOBAL_MARSHALLER);
 }
 /** Extracts a component of a given type from the cache's internal component registry */
 public static <T> T extractGlobalComponent(
     CacheContainer cacheContainer, Class<T> componentType) {
   GlobalComponentRegistry gcr = extractGlobalComponentRegistry(cacheContainer);
   return gcr.getComponent(componentType);
 }
Esempio n. 17
0
 private void initProtobufMetadataManager(
     DefaultCacheManager cacheManager, GlobalComponentRegistry gcr) {
   ProtobufMetadataManagerImpl protobufMetadataManager = new ProtobufMetadataManagerImpl();
   gcr.registerComponent(protobufMetadataManager, ProtobufMetadataManager.class);
   registerProtobufMetadataManagerMBean(protobufMetadataManager, gcr, cacheManager.getName());
 }
  private Map<Address, Object> executeOnClusterSync(
      final ReplicableCommand command, final int timeout, boolean totalOrder, boolean distributed)
      throws Exception {
    // first invoke remotely

    if (totalOrder) {
      Map<Address, Response> responseMap =
          transport.invokeRemotely(
              transport.getMembers(),
              command,
              ResponseMode.SYNCHRONOUS_IGNORE_LEAVERS,
              timeout,
              false,
              null,
              totalOrder,
              distributed);
      Map<Address, Object> responseValues =
          new HashMap<Address, Object>(transport.getMembers().size());
      for (Map.Entry<Address, Response> entry : responseMap.entrySet()) {
        Address address = entry.getKey();
        Response response = entry.getValue();
        if (!response.isSuccessful()) {
          Throwable cause =
              response instanceof ExceptionResponse
                  ? ((ExceptionResponse) response).getException()
                  : null;
          throw new CacheException(
              "Unsuccessful response received from node " + address + ": " + response, cause);
        }
        responseValues.put(address, ((SuccessfulResponse) response).getResponseValue());
      }
      return responseValues;
    }

    Future<Map<Address, Response>> remoteFuture =
        asyncTransportExecutor.submit(
            new Callable<Map<Address, Response>>() {
              @Override
              public Map<Address, Response> call() throws Exception {
                return transport.invokeRemotely(
                    null,
                    command,
                    ResponseMode.SYNCHRONOUS_IGNORE_LEAVERS,
                    timeout,
                    true,
                    null,
                    false,
                    false);
              }
            });

    // invoke the command on the local node
    gcr.wireDependencies(command);
    Response localResponse;
    try {
      if (log.isTraceEnabled()) log.tracef("Attempting to execute command on self: %s", command);
      localResponse = (Response) command.perform(null);
    } catch (Throwable throwable) {
      throw new Exception(throwable);
    }
    if (!localResponse.isSuccessful()) {
      throw new CacheException("Unsuccessful local response: " + localResponse);
    }

    // wait for the remote commands to finish
    Map<Address, Response> responseMap = remoteFuture.get(timeout, TimeUnit.MILLISECONDS);

    // parse the responses
    Map<Address, Object> responseValues =
        new HashMap<Address, Object>(transport.getMembers().size());
    for (Map.Entry<Address, Response> entry : responseMap.entrySet()) {
      Address address = entry.getKey();
      Response response = entry.getValue();
      if (!response.isSuccessful()) {
        Throwable cause =
            response instanceof ExceptionResponse
                ? ((ExceptionResponse) response).getException()
                : null;
        throw new CacheException(
            "Unsuccessful response received from node " + address + ": " + response, cause);
      }
      responseValues.put(address, ((SuccessfulResponse) response).getResponseValue());
    }

    responseValues.put(
        transport.getAddress(), ((SuccessfulResponse) localResponse).getResponseValue());

    return responseValues;
  }