@Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode newValue = operation.require(CacheContainerResource.PROTO_URL.getName());
    String urlString = newValue.asString();

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String cacheContainerName = address.getElement(address.size() - 1).getValue();
    final ServiceController<?> controller =
        context
            .getServiceRegistry(false)
            .getService(EmbeddedCacheManagerService.getServiceName(cacheContainerName));

    EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) controller.getValue();
    ProtobufMetadataManager protoManager =
        cacheManager.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class);
    if (protoManager != null) {
      try {
        URL url = new URL(urlString);
        protoManager.registerProtofile(url.openStream());
      } catch (Exception e) {
        throw new OperationFailedException(
            new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
      }
    }
    context.stepCompleted();
  }
Ejemplo n.º 2
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);
    }
  }