public static void main(String[] args) throws Exception {
    DevelopmentProvider dtp = new DevelopmentProvider();

    Topology t = dtp.newTopology("DevelopmentSampleJobMXBean");

    Random r = new Random();

    TStream<Double> d = t.poll(() -> r.nextGaussian(), 100, TimeUnit.MILLISECONDS);

    d.sink(tuple -> System.out.print("."));

    dtp.submit(t);

    System.out.println(dtp.getServices().getService(HttpServer.class).getConsoleUrl());

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    StringBuffer sbuf = new StringBuffer();
    sbuf.append(DevelopmentProvider.JMX_DOMAIN);
    sbuf.append(":interface=");
    sbuf.append(ObjectName.quote("quarks.execution.mbeans.JobMXBean"));
    sbuf.append(",type=");
    sbuf.append(ObjectName.quote("job"));
    sbuf.append(",*");

    System.out.println("Looking for MBeans of type job: " + sbuf.toString());

    ObjectName jobObjName = new ObjectName(sbuf.toString());
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);
    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();

    while (jobIterator.hasNext()) {
      ObjectInstance jobInstance = jobIterator.next();
      ObjectName objectName = jobInstance.getObjectName();

      String jobId = (String) mBeanServer.getAttribute(objectName, "Id");
      String jobName = (String) mBeanServer.getAttribute(objectName, "Name");
      String jobCurState = (String) mBeanServer.getAttribute(objectName, "CurrentState");
      String jobNextState = (String) mBeanServer.getAttribute(objectName, "NextState");
      String jobHealth = (String) mBeanServer.getAttribute(objectName, "Health");
      String jobLastError = (String) mBeanServer.getAttribute(objectName, "LastError");

      System.out.println(
          "Found a job with JobId: "
              + jobId
              + " Name: "
              + jobName
              + " CurrentState: "
              + jobCurState
              + " NextState: "
              + jobNextState
              + " Health: "
              + jobHealth
              + " LastError: \""
              + jobLastError
              + "\"");
    }
  }
Пример #2
0
 /**
  * Returns the ObjectName used by QueueControl.
  *
  * @see QueueControl
  */
 public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name)
     throws Exception {
   return ObjectName.getInstance(
       String.format(
           "%s:module=%s,type=%s,address=%s,name=%s",
           domain,
           ObjectNameBuilder.CORE_MODULE,
           "Queue",
           ObjectName.quote(address.toString()),
           ObjectName.quote(name.toString())));
 }
 public static ObjectName getCacheObjectName(
     String jmxDomain, String cacheName, String component, String cacheManagerName)
     throws Exception {
   return new ObjectName(
       jmxDomain
           + ":type=Cache,manager="
           + ObjectName.quote(cacheManagerName)
           + ",name="
           + ObjectName.quote(cacheName)
           + ",component="
           + component);
 }
Пример #4
0
    private PatternBinding(
        int hasCode,
        @NotNull String verb,
        @Nullable String route,
        @NotNull Pattern pattern,
        @Nullable Set<String> paramNames,
        @NotNull Middleware[] middleware) {
      this.route = route;
      this.pattern = pattern;
      this.paramNames = paramNames;
      Collections.addAll(this.middleware, middleware);

      // register on JMX
      try {
        objectName =
            new ObjectName(
                "com.jetdrone.yoke:type=Route@"
                    + hasCode
                    + ",method="
                    + verb
                    + ",path="
                    + ObjectName.quote(route));
      } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
      }

      try {
        mbs.registerMBean(new RouteMBean(this.middleware), objectName);
      } catch (InstanceAlreadyExistsException e) {
        // ignore
      } catch (MBeanRegistrationException | NotCompliantMBeanException e) {
        throw new RuntimeException(e);
      }
    }
Пример #5
0
  protected void startJGroupsChannelIfNeeded() {
    if (startChannel) {
      String clusterName = configuration.getClusterName();
      try {
        channel.connect(clusterName);
      } catch (Exception e) {
        throw new CacheException("Unable to start JGroups Channel", e);
      }

      try {
        // Normally this would be done by CacheManagerJmxRegistration but
        // the channel is not started when the cache manager starts but
        // when first cache starts, so it's safer to do it here.
        globalStatsEnabled = configuration.isExposeGlobalJmxStatistics();
        if (globalStatsEnabled) {
          String groupName =
              String.format("type=channel,cluster=%s", ObjectName.quote(clusterName));
          mbeanServer = JmxUtil.lookupMBeanServer(configuration);
          domain = JmxUtil.buildJmxDomain(configuration, mbeanServer, groupName);
          JmxConfigurator.registerChannel(
              (JChannel) channel, mbeanServer, domain, clusterName, true);
        }
      } catch (Exception e) {
        throw new CacheException("Channel connected, but unable to register MBeans", e);
      }
    }
    address = fromJGroupsAddress(channel.getAddress());
    if (!startChannel) {
      // the channel was already started externally, we need to initialize our member list
      viewAccepted(channel.getView());
    }
    if (log.isInfoEnabled()) log.localAndPhysicalAddress(getAddress(), getPhysicalAddresses());
  }
Пример #6
0
 private static String createMBeanName(
     String group, String type, String name, Pair<String, String>... tags) {
   final StringBuilder nameBuilder = new StringBuilder();
   nameBuilder.append(ObjectName.quote(group));
   nameBuilder.append(":type=");
   nameBuilder.append(ObjectName.quote(type));
   if (name.length() > 0) {
     nameBuilder.append(",name=");
     nameBuilder.append(ObjectName.quote(name));
   }
   for (Pair<String, String> tag : tags) {
     if (tag != null) {
       nameBuilder.append(",");
       nameBuilder.append(tag._1);
       nameBuilder.append("=");
       nameBuilder.append(tag._2);
     }
   }
   return nameBuilder.toString();
 }
Пример #7
0
  private void registerMember(Member member) {
    // JMX registration
    StringBuilder name = new StringBuilder("type=Cluster");
    Container container = getContainer();
    if (container != null) {
      name.append(container.getMBeanKeyProperties());
    }
    name.append(",component=Member,name=");
    name.append(ObjectName.quote(member.getName()));

    ObjectName oname = register(member, name.toString());
    memberOnameMap.put(member, oname);
  }
Пример #8
0
 public static ObjectName buildObjectName(ObjectName mapName, Object key) throws Exception {
   StringBuffer sb = new StringBuffer();
   sb.append(mapName.getDomain()).append(':');
   sb.append(mapName.getKeyPropertyListString());
   sb.append(',');
   if (key instanceof String) {
     sb.append("key=").append(ObjectName.quote(key.toString()));
   } else {
     sb.append("name=")
         .append(key.getClass().getName())
         .append('@')
         .append(Integer.toHexString(key.hashCode()));
   }
   return new ObjectName(sb.toString());
 }
  /**
   * Create an <code>ObjectName</code> for this <code>ContextResource</code> object.
   *
   * @param resource The resource
   * @return ObjectName The object name
   * @exception MalformedObjectNameException if a name cannot be created
   */
  protected ObjectName createObjectName(ContextResource resource)
      throws MalformedObjectNameException {

    String domain = null;
    if (container instanceof StandardServer) {
      domain = ((StandardServer) container).getDomain();
    } else if (container instanceof ContainerBase) {
      domain = ((ContainerBase) container).getDomain();
    }
    if (domain == null) {
      domain = "Catalina";
    }

    ObjectName name = null;
    String quotedResourceName = ObjectName.quote(resource.getName());
    if (container instanceof Server) {
      name =
          new ObjectName(
              domain
                  + ":type=DataSource"
                  + ",class="
                  + resource.getType()
                  + ",name="
                  + quotedResourceName);
    } else if (container instanceof Context) {
      String contextName = ((Context) container).getName();
      if (!contextName.startsWith("/")) contextName = "/" + contextName;
      Host host = (Host) ((Context) container).getParent();
      name =
          new ObjectName(
              domain
                  + ":type=DataSource"
                  + ",host="
                  + host.getName()
                  + ",context="
                  + contextName
                  + ",class="
                  + resource.getType()
                  + ",name="
                  + quotedResourceName);
    }

    return (name);
  }
  private void registerJMX() {
    String parentName = context.getName();
    if (!parentName.startsWith("/")) {
      parentName = "/" + parentName;
    }

    String hostName = context.getParent().getName();
    hostName = (hostName == null) ? "DEFAULT" : hostName;

    // domain == engine name
    String domain = context.getParent().getParent().getName();

    String webMod = "//" + hostName + parentName;
    String onameStr = null;
    String filterName = filterDef.getFilterName();
    if (Util.objectNameValueNeedsQuote(filterName)) {
      filterName = ObjectName.quote(filterName);
    }
    if (context instanceof StandardContext) {
      StandardContext standardContext = (StandardContext) context;
      onameStr =
          domain
              + ":j2eeType=Filter,WebModule="
              + webMod
              + ",name="
              + filterName
              + ",J2EEApplication="
              + standardContext.getJ2EEApplication()
              + ",J2EEServer="
              + standardContext.getJ2EEServer();
    } else {
      onameStr = domain + ":j2eeType=Filter,name=" + filterName + ",WebModule=" + webMod;
    }
    try {
      oname = new ObjectName(onameStr);
      Registry.getRegistry(null, null).registerComponent(this, oname, null);
    } catch (Exception ex) {
      log.info(
          sm.getString(
              "applicationFilterConfig.jmxRegisterFail", getFilterClass(), getFilterName()),
          ex);
    }
  }
Пример #11
0
 /**
  * The name will be prefix-address-port if address is non-null and prefix-port if the address is
  * null. The name will be appropriately quoted so it can be used directly in an ObjectName.
  */
 public String getName() {
   StringBuilder name = new StringBuilder(getNamePrefix());
   name.append('-');
   if (getAddress() != null) {
     name.append(getAddress().getHostAddress());
     name.append('-');
   }
   int port = getPort();
   if (port == 0) {
     // Auto binding is in use. Check if port is known
     name.append("auto-");
     name.append(getNameIndex());
     port = getLocalPort();
     if (port != -1) {
       name.append('-');
       name.append(port);
     }
   } else {
     name.append(port);
   }
   return ObjectName.quote(name.toString());
 }
Пример #12
0
  private ObjectName createObjectName() throws MalformedObjectNameException {
    // Use the same domain as the connector
    domain = adapter.getDomain();

    if (domain == null) {
      return null;
    }

    StringBuilder name = new StringBuilder(getDomain());
    name.append(":type=ProtocolHandler,port=");
    int port = getPort();
    if (port > 0) {
      name.append(getPort());
    } else {
      name.append("auto-");
      name.append(getNameIndex());
    }
    InetAddress address = getAddress();
    if (address != null) {
      name.append(",address=");
      name.append(ObjectName.quote(address.getHostAddress()));
    }
    return new ObjectName(name.toString());
  }
Пример #13
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);
    }
  }
Пример #14
0
  public static PoolConfiguration parsePoolProperties(Properties properties) {
    PoolConfiguration poolProperties = new PoolProperties();
    String value = null;

    value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
    if (value != null) {
      poolProperties.setDefaultAutoCommit(Boolean.valueOf(value));
    }

    value = properties.getProperty(PROP_DEFAULTREADONLY);
    if (value != null) {
      poolProperties.setDefaultReadOnly(Boolean.valueOf(value));
    }

    value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION);
    if (value != null) {
      int level = UNKNOWN_TRANSACTIONISOLATION;
      if ("NONE".equalsIgnoreCase(value)) {
        level = Connection.TRANSACTION_NONE;
      } else if ("READ_COMMITTED".equalsIgnoreCase(value)) {
        level = Connection.TRANSACTION_READ_COMMITTED;
      } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) {
        level = Connection.TRANSACTION_READ_UNCOMMITTED;
      } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) {
        level = Connection.TRANSACTION_REPEATABLE_READ;
      } else if ("SERIALIZABLE".equalsIgnoreCase(value)) {
        level = Connection.TRANSACTION_SERIALIZABLE;
      } else {
        try {
          level = Integer.parseInt(value);
        } catch (NumberFormatException e) {
          System.err.println("Could not parse defaultTransactionIsolation: " + value);
          System.err.println("WARNING: defaultTransactionIsolation not set");
          System.err.println("using default value of database driver");
          level = UNKNOWN_TRANSACTIONISOLATION;
        }
      }
      poolProperties.setDefaultTransactionIsolation(level);
    }

    value = properties.getProperty(PROP_DEFAULTCATALOG);
    if (value != null) {
      poolProperties.setDefaultCatalog(value);
    }

    value = properties.getProperty(PROP_DRIVERCLASSNAME);
    if (value != null) {
      poolProperties.setDriverClassName(value);
    }

    value = properties.getProperty(PROP_MAXACTIVE);
    if (value != null) {
      poolProperties.setMaxActive(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MAXIDLE);
    if (value != null) {
      poolProperties.setMaxIdle(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MINIDLE);
    if (value != null) {
      poolProperties.setMinIdle(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_INITIALSIZE);
    if (value != null) {
      poolProperties.setInitialSize(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MAXWAIT);
    if (value != null) {
      poolProperties.setMaxWait(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_TESTONBORROW);
    if (value != null) {
      poolProperties.setTestOnBorrow(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_TESTONRETURN);
    if (value != null) {
      poolProperties.setTestOnReturn(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_TESTONCONNECT);
    if (value != null) {
      poolProperties.setTestOnConnect(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS);
    if (value != null) {
      poolProperties.setTimeBetweenEvictionRunsMillis(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN);
    if (value != null) {
      poolProperties.setNumTestsPerEvictionRun(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS);
    if (value != null) {
      poolProperties.setMinEvictableIdleTimeMillis(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_TESTWHILEIDLE);
    if (value != null) {
      poolProperties.setTestWhileIdle(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_PASSWORD);
    if (value != null) {
      poolProperties.setPassword(value);
    }

    value = properties.getProperty(PROP_URL);
    if (value != null) {
      poolProperties.setUrl(value);
    }

    value = properties.getProperty(PROP_USERNAME);
    if (value != null) {
      poolProperties.setUsername(value);
    }

    value = properties.getProperty(PROP_VALIDATIONQUERY);
    if (value != null) {
      poolProperties.setValidationQuery(value);
    }

    value = properties.getProperty(PROP_VALIDATOR_CLASS_NAME);
    if (value != null) {
      poolProperties.setValidatorClassName(value);
    }

    value = properties.getProperty(PROP_VALIDATIONINTERVAL);
    if (value != null) {
      poolProperties.setValidationInterval(Long.parseLong(value));
    }

    value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED);
    if (value != null) {
      poolProperties.setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_REMOVEABANDONED);
    if (value != null) {
      poolProperties.setRemoveAbandoned(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT);
    if (value != null) {
      poolProperties.setRemoveAbandonedTimeout(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_LOGABANDONED);
    if (value != null) {
      poolProperties.setLogAbandoned(Boolean.valueOf(value).booleanValue());
    }

    value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS);
    if (value != null) {
      log.warn(PROP_POOLPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
    }

    value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS);
    if (value != null) {
      log.warn(PROP_MAXOPENPREPAREDSTATEMENTS + " is not a valid setting, it will have no effect.");
    }

    value = properties.getProperty(PROP_CONNECTIONPROPERTIES);
    if (value != null) {
      Properties p = getProperties(value);
      poolProperties.setDbProperties(p);
    } else {
      poolProperties.setDbProperties(new Properties());
    }

    if (poolProperties.getUsername() != null) {
      poolProperties.getDbProperties().setProperty("user", poolProperties.getUsername());
    }
    if (poolProperties.getPassword() != null) {
      poolProperties.getDbProperties().setProperty("password", poolProperties.getPassword());
    }

    value = properties.getProperty(PROP_INITSQL);
    if (value != null) {
      poolProperties.setInitSQL(value);
    }

    value = properties.getProperty(PROP_INTERCEPTORS);
    if (value != null) {
      poolProperties.setJdbcInterceptors(value);
    }

    value = properties.getProperty(PROP_JMX_ENABLED);
    if (value != null) {
      poolProperties.setJmxEnabled(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_FAIR_QUEUE);
    if (value != null) {
      poolProperties.setFairQueue(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_USE_EQUALS);
    if (value != null) {
      poolProperties.setUseEquals(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(OBJECT_NAME);
    if (value != null) {
      poolProperties.setName(ObjectName.quote(value));
    }

    value = properties.getProperty(PROP_ABANDONWHENPERCENTAGEFULL);
    if (value != null) {
      poolProperties.setAbandonWhenPercentageFull(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_MAXAGE);
    if (value != null) {
      poolProperties.setMaxAge(Long.parseLong(value));
    }

    value = properties.getProperty(PROP_USE_CON_LOCK);
    if (value != null) {
      poolProperties.setUseLock(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_DATASOURCE);
    if (value != null) {
      // this should never happen
      throw new IllegalArgumentException(
          "Can't set dataSource property as a string, this must be a javax.sql.DataSource object.");
    }

    value = properties.getProperty(PROP_DATASOURCE_JNDI);
    if (value != null) {
      poolProperties.setDataSourceJNDI(value);
    }

    value = properties.getProperty(PROP_SUSPECT_TIMEOUT);
    if (value != null) {
      poolProperties.setSuspectTimeout(Integer.parseInt(value));
    }

    value = properties.getProperty(PROP_ALTERNATE_USERNAME_ALLOWED);
    if (value != null) {
      poolProperties.setAlternateUsernameAllowed(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_COMMITONRETURN);
    if (value != null) {
      poolProperties.setCommitOnReturn(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_ROLLBACKONRETURN);
    if (value != null) {
      poolProperties.setRollbackOnReturn(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_USEDISPOSABLECONNECTIONFACADE);
    if (value != null) {
      poolProperties.setUseDisposableConnectionFacade(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_LOGVALIDATIONERRORS);
    if (value != null) {
      poolProperties.setLogValidationErrors(Boolean.parseBoolean(value));
    }

    value = properties.getProperty(PROP_PROPAGATEINTERRUPTSTATE);
    if (value != null) {
      poolProperties.setPropagateInterruptState(Boolean.parseBoolean(value));
    }

    return poolProperties;
  }
Пример #15
0
 private String getQueryGroupName(String cacheName) {
   return "type=Query,name=" + ObjectName.quote(cacheName);
 }
 public static ObjectName getJGroupsChannelObjectName(String jmxDomain, String clusterName)
     throws Exception {
   return new ObjectName(
       String.format("%s:type=channel,cluster=%s", jmxDomain, ObjectName.quote(clusterName)));
 }
Пример #17
0
 public static String quote(String text) {
   return Pattern.compile("[:\",=*?]").matcher(text).find() ? ObjectName.quote(text) : text;
 }
Пример #18
0
 private ObjectName createObjectName(final String module, final String type, final String name)
     throws Exception {
   return ObjectName.getInstance(
       String.format(
           "%s:module=%s,type=%s,name=%s", domain, module, type, ObjectName.quote(name)));
 }