gedi-geode-extensions-core/src/main/java/gedi/solutions/geode/client/GemFireJmxClient.java
public static synchronized ClientCache getClientCache(JMX jmx)
	{
		try
		{
			if (clientCache == null || clientCache.isClosed())
			{

				try
				{
					clientCache = ClientCacheFactory.getAnyInstance();
				}
				catch(CacheClosedException e)
				{
					clientCache = null;
				}
				
				if (clientCache != null)
					return clientCache;

				
				// Get Locator port
				// locator bean GemFire:service=Locator,type=Member,member=locator
				String locatorNamePattern = "GemFire:type=Member,member=*";
				QueryExp queryExp = Query.eq(Query.attr("Manager"), Query.value(true));
				Set<ObjectName> objectNames = jmx.searchObjectNames(locatorNamePattern,
						queryExp);

				if (objectNames == null || objectNames.isEmpty())
				{
					throw new RuntimeException(
							"Data export error: no manager locators found through JMX connection");
				}

				ObjectName locatorJmxMgrObjName = objectNames.iterator().next();

				String locatorMemberName = jmx.getAttribute(locatorJmxMgrObjName,
						"Member");

				ObjectName locatorServiceObjName = new ObjectName(String.format(
						"GemFire:service=Locator,type=Member,member=%s",
						locatorMemberName));

				// get port
				
				int port = jmx.getAttribute(locatorServiceObjName, "Port");
				String host = jmx.getAttribute(locatorJmxMgrObjName, "Host");
				
				
				host = lookupNetworkHost(host);
				
				clientCache = new ClientCacheFactory().addPoolLocator(
						host, port)
						.setPoolSubscriptionEnabled(false)
						.setPdxReadSerialized(
								Boolean.valueOf(
										System.getProperty("PdxReadSerialized","false"))
										.booleanValue()
								)
						.create();
				
			}
			
			return clientCache;
		}
		catch(RuntimeException e)
		{
			throw e;
		}
		catch (Exception e)
		{
			throw new RuntimeException("JMX connection error "+e.getMessage(),e);
		}
	}
public static synchronized ClientCache getClientCache(JMX jmx)
	{
		try
		{
			if (clientCache == null || clientCache.isClosed())
			{

				try
				{
					clientCache = ClientCacheFactory.getAnyInstance();
				}
				catch(CacheClosedException e)
				{
					clientCache = null;
				}
				
				if (clientCache != null)
					return clientCache;

				
				// Get Locator port
				// locator bean GemFire:service=Locator,type=Member,member=locator
				String locatorNamePattern = "GemFire:type=Member,member=*";
				QueryExp queryExp = Query.eq(Query.attr("Manager"), Query.value(true));
				Set<ObjectName> objectNames = jmx.searchObjectNames(locatorNamePattern,
						queryExp);

				if (objectNames == null || objectNames.isEmpty())
				{
					throw new RuntimeException(
							"Data export error: no manager locators found through JMX connection");
				}

				ObjectName locatorJmxMgrObjName = objectNames.iterator().next();

				String locatorMemberName = jmx.getAttribute(locatorJmxMgrObjName,
						"Member");

				ObjectName locatorServiceObjName = new ObjectName(String.format(
						"GemFire:service=Locator,type=Member,member=%s",
						locatorMemberName));

				// get port
				
				int port = jmx.getAttribute(locatorServiceObjName, "Port");
				String host = jmx.getAttribute(locatorJmxMgrObjName, "Host");
				
				
				host = lookupNetworkHost(host);
				
				clientCache = new ClientCacheFactory().addPoolLocator(
						host, port)
						.setPoolSubscriptionEnabled(false)
						.setPdxReadSerialized(
								Boolean.valueOf(
										System.getProperty("PdxReadSerialized","false"))
										.booleanValue()
								)
						.create();
				
			}
			
			return clientCache;
		}
		catch(RuntimeException e)
		{
			throw e;
		}
		catch (Exception e)
		{
			throw new RuntimeException("JMX connection error "+e.getMessage(),e);
		}
	}
Return the client cache based on the JMX connection (if no cache instance)
@param jmx the gemfire JMX manager connection
@return the Client cache instance