[18/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-11-15 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b6c305f8/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
new file mode 100644
index 000..932fe21
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/AgentLauncher.java
@@ -0,0 +1,918 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.SortedMap;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.GemFireException;
+import org.apache.geode.SystemFailure;
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.jmx.Agent;
+import org.apache.geode.internal.admin.api.jmx.AgentConfig;
+import org.apache.geode.internal.admin.api.jmx.AgentFactory;
+import org.apache.geode.distributed.internal.DistributionManager;
+import org.apache.geode.internal.OSProcess;
+import org.apache.geode.internal.PureJavaMode;
+import org.apache.geode.internal.net.SocketCreator;
+import org.apache.geode.internal.i18n.LocalizedStrings;
+import org.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.util.IOUtils;
+import org.apache.geode.internal.util.JavaCommandBuilder;
+
+/**
+ * A command line utility inspired by the CacheServerLauncher 
that is responsible for
+ * administering a stand-along GemFire JMX {@link Agent}.
+ * 
+ * 
+ * @since GemFire 3.5
+ */
+public class AgentLauncher {
+
+  private static final Logger logger = LogService.getLogger();
+
+  /** Should the launch command be printed? */
+  public static final boolean PRINT_LAUNCH_COMMAND =
+  Boolean.getBoolean(AgentLauncher.class.getSimpleName() + 
".PRINT_LAUNCH_COMMAND");
+
+  /* constants used to define state */
+  static final int SHUTDOWN = 0;
+  static final int STARTING = 1;
+  static final int RUNNING = 2;
+  static final int SHUTDOWN_PENDING = 3;
+  static final int SHUTDOWN_PENDING_AFTER_FAILED_STARTUP = 4;
+  static final int UNKNOWN = 6;
+
+  /** Agent configuration options */
+  static final String AGENT_PROPS = "agent-props";
+
+  /**
+   * A flag to indicate if the current log file should be kept. Used only when 
'start' is used to
+   * fork off the 'server'
+   */
+  static final String APPENDTO_LOG_FILE = "appendto-log-file";
+
+  /** optional and additional classpath entries */
+  static final String CLASSPATH = "classpath";
+
+  /** The directory argument */
+  static final String DIR = "dir";
+
+  /** Extra VM arguments */
+  static final String VMARGS = "vmargs";
+
+  /** The directory in which the agent's output resides */
+  private File workingDirectory = null;
+
+  /** The Status object for the agent */
+  private Status status = null;
+
+  /** base name for the agent to be launched */
+  private final String basename;
+
+  /** The name for the start up log file */
+  private final String startLogFileName;
+
+  /** The name of the status file */
+  private final String statusFileName;
+
+  /**
+   * Instantiates an AgentLauncher for execution and control of the GemFire 
JMX Agent process. This
+   * constructor is package private to prevent direct instantiation or 
subclassing by classes
+   * outside this package, but does allow the class to be tested as needed.
+   * 
+   * 
+   * @param basename base name for the application to be launched
+   */
+  AgentLauncher(final 

[18/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-11-07 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6bb27bf1/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
new file mode 100644
index 000..23e9038
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/GemFireHealthConfigJmxImpl.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import javax.management.ObjectName;
+import javax.management.modelmbean.ModelMBean;
+
+import org.apache.geode.internal.admin.api.AdminException;
+import org.apache.geode.internal.admin.api.GemFireHealth;
+import org.apache.geode.internal.admin.api.GemFireHealthConfig;
+import org.apache.geode.internal.admin.api.impl.GemFireHealthConfigImpl;
+
+/**
+ * The JMX "managed resource" that represents the configuration for the health 
of GemFire.
+ * Basically, it provides the behavior of 
GemFireHealthConfigImpl, but does some JMX
+ * stuff like registering beans with the agent.
+ *
+ * 
+ *
+ * Unlike other ManagedResources this class cannot simply subclass
+ * GemFireHealthImpl because it instances are serialized and sent 
to other VMs. This is
+ * problematic because the other VMs most likely do not have JMX classes like
+ * ModelMBean on their classpaths. So, instead we delegate all of 
the
+ * GemFireHealthConfig behavior to another object which IS 
serialized.
+ *
+ * @see GemFireHealthJmxImpl#createDistributedSystemHealthConfig
+ *
+ *
+ * @since GemFire 3.5
+ */
+@edu.umd.cs.findbugs.annotations.SuppressWarnings(
+justification = "This class is deprecated. Also, any further changes so 
close to the release is inadvisable.")
+public class GemFireHealthConfigJmxImpl
+implements GemFireHealthConfig, ManagedResource, java.io.Serializable {
+
+  private static final long serialVersionUID = 1482719647163239953L;
+
+  /** The GemFireHealth that we help configure */
+  private GemFireHealth health;
+
+  /** The name of the MBean that will manage this resource */
+  private String mbeanName;
+
+  /** The ModelMBean that is configured to manage this resource */
+  private ModelMBean modelMBean;
+
+  /** The delegate that contains the real config state */
+  private GemFireHealthConfig delegate;
+
+  /** The object name of this managed resource */
+  private ObjectName objectName;
+
+  /// Constructors ///
+
+  /**
+   * Creates a new GemFireHealthConfigJmxImpl that configures the 
health monitoring of
+   * components running on the given host.
+   */
+  GemFireHealthConfigJmxImpl(GemFireHealthJmxImpl health, String hostName) 
throws AdminException {
+
+this.delegate = new GemFireHealthConfigImpl(hostName);
+this.health = health;
+this.mbeanName = new 
StringBuffer().append(MBEAN_NAME_PREFIX).append("GemFireHealthConfig,id=")
+
.append(MBeanUtil.makeCompliantMBeanNameProperty(health.getDistributedSystem().getId()))
+.append(",host=")
+.append((hostName == null ? "default" : 
MBeanUtil.makeCompliantMBeanNameProperty(hostName)))
+.toString();
+this.objectName = MBeanUtil.createMBean(this);
+  }
+
+  // Instance Methods //
+
+  /**
+   * Applies the changes made to this config back to the health monitor.
+   *
+   * @see GemFireHealth#setDistributedSystemHealthConfig
+   */
+  public void applyChanges() {
+String hostName = this.getHostName();
+if (hostName == null) {
+  this.health.setDefaultGemFireHealthConfig(this);
+
+} else {
+  this.health.setGemFireHealthConfig(hostName, this);
+}
+  }
+
+  public String getMBeanName() {
+return this.mbeanName;
+  }
+
+  public ModelMBean getModelMBean() {
+return this.modelMBean;
+  }
+
+  public ObjectName getObjectName() {
+return this.objectName;
+  }
+
+  public void setModelMBean(ModelMBean modelMBean) {
+

[18/50] [abbrv] incubator-geode git commit: GEODE-288: move admin packages to internal

2016-10-27 Thread klund
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/20a32286/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/MX4JModelMBean.java
--
diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/MX4JModelMBean.java
 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/MX4JModelMBean.java
new file mode 100755
index 000..2facc17
--- /dev/null
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/admin/api/jmx/impl/MX4JModelMBean.java
@@ -0,0 +1,1232 @@
+/*
+ * Copyright (C) MX4J. All rights reserved.
+ *
+ * This software is distributed under the terms of the MX4J License version 
1.0. See the terms of
+ * the MX4J License in the documentation provided with this software.
+ */
+
+package org.apache.geode.internal.admin.api.jmx.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.management.Attribute;
+import javax.management.AttributeChangeNotification;
+import javax.management.AttributeChangeNotificationFilter;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.Descriptor;
+import javax.management.InstanceNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.RuntimeErrorException;
+import javax.management.RuntimeOperationsException;
+import javax.management.ServiceNotFoundException;
+import javax.management.loading.ClassLoaderRepository;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+import javax.management.modelmbean.ModelMBean;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+
+import mx4j.ImplementationException;
+import mx4j.log.FileLogger;
+import mx4j.log.Log;
+import mx4j.log.Logger;
+import mx4j.log.MBeanLogger;
+import mx4j.persist.FilePersister;
+import mx4j.persist.MBeanPersister;
+import mx4j.persist.PersisterMBean;
+import mx4j.util.Utils;
+
+import org.apache.geode.internal.i18n.LocalizedStrings;
+
+/**
+ * @author mailto:biorn_stee...@users.sourceforge.net;>Simone 
Bordet
+ * @version $Revision: 1.14 $
+ */
+public class MX4JModelMBean implements ModelMBean, MBeanRegistration, 
NotificationEmitter {
+  private static final String OBJECT_RESOURCE_TYPE = "ObjectReference";
+
+  private static final int ALWAYS_STALE = 1;
+  private static final int NEVER_STALE = 2;
+  private static final int STALE = 3;
+  private static final int NOT_STALE = 4;
+
+  private static final int PERSIST_NEVER = -1;
+  private static final int PERSIST_ON_TIMER = -2;
+  private static final int PERSIST_ON_UPDATE = -3;
+  private static final int PERSIST_NO_MORE_OFTEN_THAN = -4;
+
+  private MBeanServer m_mbeanServer;
+  private Object m_managedResource;
+  private boolean m_canBeRegistered;
+  private ModelMBeanInfo m_modelMBeanInfo;
+  private NotificationBroadcasterSupport m_attributeChangeBroadcaster =
+  new NotificationBroadcasterSupport();
+  private NotificationBroadcasterSupport m_generalBroadcaster =
+  new NotificationBroadcasterSupport();
+
+  public MX4JModelMBean() throws MBeanException, RuntimeOperationsException {
+try {
+  load();
+} catch (Exception x) {
+  Logger logger = getLogger();
+  
logger.warn(LocalizedStrings.MX4JModelMBean_CANNOT_RESTORE_PREVIOUSLY_SAVED_STATUS
+  .toLocalizedString(), x);
+}
+  }
+
+  public MX4JModelMBean(ModelMBeanInfo info) throws MBeanException, 
RuntimeOperationsException {
+if (info == null)
+  throw new RuntimeOperationsException(new IllegalArgumentException(
+  LocalizedStrings.MX4JModelMBean_MODELMBEANINFO_PARAMETER_CANT_BE_NULL
+  .toLocalizedString()));
+else
+  setModelMBeanInfo(info);
+  }
+
+  private Logger getLogger() {
+return Log.getLogger(getClass().getName());
+  }
+
+  public ObjectName preRegister(MBeanServer server, ObjectName name) throws 
Exception {
+if (m_canBeRegistered) {
+  m_mbeanServer