Summary: Allows you to retrieve connections to the space, using GigaSpaces API and JMX.

Overview

It is possible to retrieve connections to the space, using GigaSpaces API and JMX. To do this:

  1. Find a space using com.j_spaces.core.client.SpaceFinder.
  2. Create an MBeanServerConnection, using a JNDI URL from the space container, as part of the JMX service URL.
  3. Invoke the appropriate method on the MBean using an MBeanServerConnection.

It is also possible to retrieve space connections using the space connections command, or the GigaSpaces UI Connections view.

Example

ConnectionsTest.java
package com.jmx.connections;

import java.io.IOException;
import java.util.List;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import com.gigaspaces.lrmi.TransportProtocolHelper;
import com.gigaspaces.management.transport.ITransportConnection;
import com.gigaspaces.management.transport.TransportConstants;
import com.j_spaces.core.IJSpace;
import com.j_spaces.core.admin.IJSpaceContainerAdmin;
import com.j_spaces.core.admin.IRemoteJSpaceAdmin;
import com.j_spaces.core.client.IDirectSpaceProxy;
import com.j_spaces.core.client.SpaceFinder;

public class ConnectionsTest
{
    public ConnectionsTest()
    {
        try
        {
            //find "mySpace" space
            IJSpace spaceProxy = 
                ( IJSpace )SpaceFinder.find( "jini://localhost/mySpace_container/mySpace" );

            System.out.println( "Space found....." );
            
            //retrieve space container
            IJSpaceContainerAdmin containerProxy = ( IJSpaceContainerAdmin )spaceProxy.getContainer();

            System.out.println( "Space container retrieved...." );
            
            //retrieve space remote admin object
            IRemoteJSpaceAdmin remoteAdminSpace = 
                ( IRemoteJSpaceAdmin )((IDirectSpaceProxy)spaceProxy).getRemoteJSpace();

            //get remote space id
            long objID = TransportProtocolHelper.getRemoteObjID( remoteAdminSpace );        

            System.out.println( "Space remote space ID retrieved...." + objID );
            
            //create MBean server connection
            MBeanServerConnection beanServerConnection = 
                                createJMXConnection( containerProxy.getConfig().jndiUrl );

            System.out.println( "MBean Server connection created...." );
            
            String containerName = containerProxy.getName();
            
            ObjectName mBeanName = 
                TransportConstants.createTransportMBeanObjectName( containerName );

            Object[] params = { new Long( objID ) };
            String[] signature = { long.class.getName() };
            //invoke MBean getTransportConnections(long) method
            List<ITransportConnection> list = 
                    ( List<ITransportConnection> )beanServerConnection.invoke( 
                                mBeanName, "getTransportConnections", params, signature );

            System.out.println( "Transport list:\n" + list );
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
    }
    
    private MBeanServerConnection createJMXConnection( String jndiURL ) throws IOException
    {
        JMXServiceURL url = new JMXServiceURL(
        "service:jmx:rmi:///jndi/rmi://" + jndiURL + "/jmxrmi" );

        JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
        
        return mbsc;
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        new ConnectionsTest();

    }
}
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence