com.sun.jdi.connect.Connector.Argument Java Examples

The following examples show how to use com.sun.jdi.connect.Connector.Argument. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void log(Connector c, Map<String, Argument> args) {
    LogRecord record = new LogRecord(Level.INFO, "USG_DEBUG_ATTACH_JPDA");
    record.setResourceBundle(NbBundle.getBundle(ConnectPanel.class));
    record.setResourceBundleName(ConnectPanel.class.getPackage().getName() + ".Bundle"); // NOI18N
    record.setLoggerName(USG_LOGGER.getName());
    List<Object> params = new ArrayList<Object>();
    params.add(c.name());
    StringBuilder arguments = new StringBuilder();
    for (Map.Entry argEntry : args.entrySet()) {
        //arguments.append(argEntry.getKey());
        //arguments.append("=");
        arguments.append(argEntry.getValue());
        arguments.append(", ");
    }
    if (arguments.length() > 2) {
        arguments.delete(arguments.length() - 2, arguments.length());
    }
    params.add(arguments);
    record.setParameters(params.toArray(new Object[params.size()]));
    USG_LOGGER.log(record);
}
 
Example #2
Source File: DebugUtility.java    From java-debug with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Attach to an existing debuggee VM.
 * @param vmManager
 *               the virtual machine manager
 * @param hostName
 *               the machine where the debuggee VM is launched on
 * @param port
 *               the debug port that the debuggee VM exposed
 * @param attachTimeout
 *               the timeout when attaching to the debuggee VM
 * @return an instance of IDebugSession
 * @throws IOException
 *               when unable to attach.
 * @throws IllegalConnectorArgumentsException
 *               when one of the connector arguments is invalid.
 */
public static IDebugSession attach(VirtualMachineManager vmManager, String hostName, int port, int attachTimeout)
        throws IOException, IllegalConnectorArgumentsException {
    List<AttachingConnector> connectors = vmManager.attachingConnectors();
    AttachingConnector connector = connectors.get(0);
    // in JDK 10, the first AttachingConnector is not the one we want
    final String SUN_ATTACH_CONNECTOR = "com.sun.tools.jdi.SocketAttachingConnector";
    for (AttachingConnector con : connectors) {
        if (con.getClass().getName().equals(SUN_ATTACH_CONNECTOR)) {
            connector = con;
            break;
        }
    }
    Map<String, Argument> arguments = connector.defaultArguments();
    arguments.get(HOSTNAME).setValue(hostName);
    arguments.get(PORT).setValue(String.valueOf(port));
    arguments.get(TIMEOUT).setValue(String.valueOf(attachTimeout));
    return new DebugSession(connector.attach(arguments));
}
 
Example #3
Source File: ConnectPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void saveArgs (
    Map<String, Argument> args,
    Connector             connector
) {
    Map<String, Argument> defaultValues = connector.defaultArguments ();
    Map<String, String> argsToSave = new HashMap<String, String>();
    for(String argName : args.keySet ()) {
        Argument value = args.get (argName);
        Argument defaultValue = defaultValues.get (argName);
        if ( value != null &&
             value != defaultValue &&
             !value.equals (defaultValue)
        ) {
            argsToSave.put (argName, value.value ());
        }
    }

    Map m = Properties.getDefault ().getProperties ("debugger").
        getMap ("connection_settings", new HashMap ());
    String name = connector.name ();
    m.put (name, argsToSave);
    Properties.getDefault ().getProperties ("debugger").
            setString ("last_attaching_connector", name);
    Properties.getDefault ().getProperties ("debugger").
            setMap ("connection_settings", m);
}
 
Example #4
Source File: GetObjectLockCount.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the launching connector's arguments.
 */
static Map <String,Connector.Argument> connectorArguments(LaunchingConnector connector, String mainArgs) {
    Map<String,Connector.Argument> arguments = connector.defaultArguments();

    Connector.Argument mainArg = (Connector.Argument)arguments.get("main");
    if (mainArg == null) {
        throw new Error("Bad launching connector");
    }
    mainArg.setValue(mainArgs);

    Connector.Argument optionsArg = (Connector.Argument)arguments.get("options");
    if (optionsArg == null) {
        throw new Error("Bad launching connector");
    }
    optionsArg.setValue(ARGUMENTS);
    return arguments;
}
 
Example #5
Source File: JPDADebugger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * This utility method helps to start a new JPDA debugger session.
 * Its implementation use {@link ListeningDICookie} and
 * {@link org.netbeans.api.debugger.DebuggerManager#getDebuggerManager}.
 * It's identical to {@link #startListening(com.sun.jdi.connect.ListeningConnector, java.util.Map, java.lang.Object[])},
 * but returns the started engines.
 *
 * @param connector The listening connector
 * @param args The arguments
 * @param services The additional services, which are added to the debugger session lookup.<br/>
 * See {@link #listen(com.sun.jdi.connect.ListeningConnector, java.util.Map, java.lang.Object[])} for a more detailed description of this argument.
 * @return A non-empty array of started engines (since 2.26)
 * @throws DebuggerStartException when {@link org.netbeans.api.debugger.DebuggerManager#startDebugging}
 * returns an empty array
 * @since 2.26
 */
public static DebuggerEngine[] startListeningAndGetEngines (
    ListeningConnector        connector,
    Map<String, ? extends Argument>  args,
    Object[]                  services
) throws DebuggerStartException {
    Object[] s = new Object [services.length + 1];
    System.arraycopy (services, 0, s, 1, services.length);
    s [0] = ListeningDICookie.create (
        connector,
        args
    );
    DebuggerEngine[] es = DebuggerManager.getDebuggerManager ().
        startDebugging (
            DebuggerInfo.create (
                ListeningDICookie.ID,
                s
            )
        );
    if (es.length == 0) {
        throw new DebuggerStartException(
                NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER"));
    }
    return es;
}
 
Example #6
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String,? extends Argument> getArgs (
    AttachingConnector attachingConnector,
    String hostName,
    int portNumber
) {
    Map<String,? extends Argument> args = attachingConnector.defaultArguments ();
    args.get ("hostname").setValue (hostName);
    args.get ("port").setValue ("" + portNumber);
    return args;
}
 
Example #7
Source File: JDIRedefiner.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
private VirtualMachine connect(int port) throws IOException {
    VirtualMachineManager manager = Bootstrap.virtualMachineManager();

    // Find appropiate connector
    List<AttachingConnector> connectors = manager.attachingConnectors();
    AttachingConnector chosenConnector = null;
    for (AttachingConnector c : connectors) {
        if (c.transport().name().equals(TRANSPORT_NAME)) {
            chosenConnector = c;
            break;
        }
    }
    if (chosenConnector == null) {
        throw new IllegalStateException("Could not find socket connector");
    }

    // Set port argument
    AttachingConnector connector = chosenConnector;
    Map<String, Argument> defaults = connector.defaultArguments();
    Argument arg = defaults.get(PORT_ARGUMENT_NAME);
    if (arg == null) {
        throw new IllegalStateException("Could not find port argument");
    }
    arg.setValue(Integer.toString(port));

    // Attach
    try {
        System.out.println("Connector arguments: " + defaults);
        return connector.attach(defaults);
    } catch (IllegalConnectorArgumentsException e) {
        throw new IllegalArgumentException("Illegal connector arguments",
                e);
    }
}
 
Example #8
Source File: Connectors.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
public boolean setMapArguments(String arg, String value, int i){
	
	Connector.Argument argument = (Connector.Argument)connectionSettings.get(i).get(arg);
	if (argument == null) {
		return false;
	}
	argument.setValue(value);
	return true;
}
 
Example #9
Source File: ListeningDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String, ? extends Argument> getArgs (
    ListeningConnector listeningConnector,
    String name
) {
    Map<String, ? extends Argument> args = listeningConnector.defaultArguments ();
    args.get ("name").setValue (name);
    return args;
}
 
Example #10
Source File: ListeningDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String, ? extends Argument> getArgs (
    ListeningConnector listeningConnector,
    int portNumber
) {
    Map<String, ? extends Argument> args = listeningConnector.defaultArguments ();
    args.get ("port").setValue (portNumber > 0 ? "" + portNumber : "");
    return args;
}
 
Example #11
Source File: ListeningDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of ListeningDICookie for given parameters.
 *
 * @param listeningConnector a instance of ListeningConnector
 * @param args arguments to be used
 * @return a new instance of ListeningDICookie for given parameters
 */
public static ListeningDICookie create (
    ListeningConnector listeningConnector,
    Map<String, ? extends Argument> args
) {
    return new ListeningDICookie (
        listeningConnector,
        args
    );
}
 
Example #12
Source File: ListeningDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ListeningDICookie (
    ListeningConnector listeningConnector,
    Map<String, ? extends Argument> args
) {
    this.listeningConnector = listeningConnector;
    this.args = args;
}
 
Example #13
Source File: LaunchingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String, ? extends Argument> getArgs (
    String commandLine,
    String address
) {
    Map<String, ? extends Argument> args = findLaunchingConnector ().defaultArguments ();
    args.get ("command").setValue (commandLine);
    args.get ("address").setValue (address);
    return args;
}
 
Example #14
Source File: LaunchingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private LaunchingDICookie (
    LaunchingConnector launchingConnector,
    Map<String, ? extends Argument> args,
    String mainClassName,
    boolean suspend
) {
    this.launchingConnector = launchingConnector;
    this.args = args;
    this.mainClassName = mainClassName;
    this.suspend = suspend;
}
 
Example #15
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Map<String,? extends Argument> getArgs (
    AttachingConnector attachingConnector,
    String name
) {
    Map<String,? extends Argument> args = attachingConnector.defaultArguments ();
    args.get ("name").setValue (name);
    return args;
}
 
Example #16
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private AttachingDICookie (
    AttachingConnector attachingConnector,
    Map<String,? extends Argument> args
) {
    this.attachingConnector = attachingConnector;
    this.args = args;
}
 
Example #17
Source File: HelloWorld.java    From java-svc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static VirtualMachine connect(String host, String port)
		throws IOException, IllegalConnectorArgumentsException {
	AttachingConnector socketConnector = getSocketConnector();
	Map<String, Argument> arguments = socketConnector.defaultArguments();
	arguments.get("hostname").setValue(host);
	((IntegerArgument) arguments.get("port")).setValue(Integer.parseInt(port));
	return socketConnector.attach(arguments);
}
 
Example #18
Source File: ConnectPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String getLabel(Argument a) {
    String label = translate (a.name());
    if (label == null) {
        label = a.label();
    } else {
        int amp = Mnemonics.findMnemonicAmpersand(label);
        if (amp >= 0) {
            label = label.substring(0, amp) + label.substring(amp + 1);
        }
    }
    return label;
}
 
Example #19
Source File: JPDADebugger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * This utility method helps to start a new JPDA debugger session. 
 * Its implementation use {@link ListeningDICookie} and 
 * {@link org.netbeans.api.debugger.DebuggerManager#getDebuggerManager}.
 *
 * @param connector The listening connector
 * @param args The arguments
 * @param services The additional services, which are added to the debugger session lookup.<br/>
 * It is expected, that one element in the services array is a {@link Map} with following setup properties:<br/>
 * <lu>
 * <li><code>name</code> with the value being the session name as String,</li>
 * <li><code>sourcepath</code> with the {@link ClassPath} value containing class path of sources used by debugger,</li>
 * <li><code>jdksources</code> with the {@link ClassPath} value containing class path of platform sources,</li>
 * <li><code>listeningCP</code> optional String representation of source class path which is in compile-on-save mode, which we listen on for artifacts changes,</li>
 * <li><code>baseDir</code> with the debugging project's base directory as {@link File}.</li>
 * </lu>
 */
public static JPDADebugger listen (
    ListeningConnector        connector,
    Map<String, ? extends Argument>  args,
    Object[]                  services
) throws DebuggerStartException {
    Object[] s = new Object [services.length + 1];
    System.arraycopy (services, 0, s, 1, services.length);
    s [0] = ListeningDICookie.create (
        connector,
        args
    );
    DebuggerEngine[] es = DebuggerManager.getDebuggerManager ().
        startDebugging (
            DebuggerInfo.create (
                ListeningDICookie.ID,
                s
            )
        );
    int i, k = es.length;
    for (i = 0; i < k; i++) {
        JPDADebugger d = es[i].lookupFirst(null, JPDADebugger.class);
        if (d == null) {
            continue;
        }
        d.waitRunning ();
        return d;
    }
    throw new DebuggerStartException(
            NbBundle.getMessage(JPDADebugger.class, "MSG_NO_DEBUGGER"));
}
 
Example #20
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of AttachingDICookie for given parameters.
 *
 * @param attachingConnector a connector to be used
 * @param args map of arguments
 * @return a new instance of AttachingDICookie for given parameters
 */
public static AttachingDICookie create (
    AttachingConnector attachingConnector,
    Map<String,? extends Argument> args
) {
    return new AttachingDICookie (
        attachingConnector, 
        args
    );
}
 
Example #21
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns port number.
 *
 * @return port number
 */
public int getPortNumber () {
    Argument a = args.get ("port");
    if (a == null) return -1;
    String pn = a.value ();
    if (pn == null) return -1;
    return Integer.parseInt (pn);
}
 
Example #22
Source File: LaunchingDICookie.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns command line to be used.
 *
 * @return command line to be used
 */
public String getCommandLine () {
    Argument a = args.get ("command");
    if (a == null) return null;
    return a.value ();
}
 
Example #23
Source File: ListeningDICookie.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns shared memory block name.
 *
 * @return shared memory block name
 */
public String getSharedMemoryName () {
    Argument a = args.get ("name");
    if (a == null) return null;
    return a.value ();
}
 
Example #24
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns name of computer.
 *
 * @return name of computer
 */
public String getHostName () {
    Argument a = args.get ("hostname");
    if (a == null) return null;
    return a.value ();
}
 
Example #25
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Returns shared memory block name.
 *
 * @return shared memory block name
 */
public String getSharedMemoryName () {
    Argument a = args.get ("name");
    if (a == null) return null;
    return a.value ();
}
 
Example #26
Source File: ConnectPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Map<String, Argument> getEditedArgs (
    JTextField[]        tfParams, 
    Connector           connector
) {
    assert SwingUtilities.isEventDispatchThread();
    // 1) get default set of args
    Map<String, Argument> args = connector.defaultArguments ();

    // 2) update values from text fields
    int i, k = tfParams.length;
    for (i = 0; i < k; i++) {
        JTextField tf = tfParams [i];
        String paramName = tf.getName ();
        String paramValue = tf.getText ();
        Argument a = args.get (paramName);
        while ( ((!a.isValid (paramValue)) && (!"".equals (paramValue))) ||
                ( "".equals (paramValue) && a.mustSpecify () )
        ) {
            NotifyDescriptor.InputLine in;
            String label = getLabel(a);
            if ( "".equals (paramValue) && a.mustSpecify ()) {
                in = new NotifyDescriptor.InputLine (
                    label,
                    NbBundle.getMessage (
                        ConnectPanel.class, 
                        "CTL_Required_value_title"
                    )
                );
            } else {
                in = new NotifyDescriptor.InputLine (
                    label,
                    NbBundle.getMessage (
                        ConnectPanel.class, 
                        "CTL_Invalid_value_title"
                    )
                );
            }
            if (DialogDisplayer.getDefault ().notify (in) == 
                NotifyDescriptor.CANCEL_OPTION
            ) {
                return null;
            }
            paramValue = in.getInputText ();
        }
        a.setValue (paramValue);
    }
    
    return args;
}
 
Example #27
Source File: JPDADebugger.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * This utility method helps to start a new JPDA debugger session. 
 * Its implementation use {@link ListeningDICookie} and 
 * {@link org.netbeans.api.debugger.DebuggerManager#getDebuggerManager}.
 *
 * @param connector The listening connector
 * @param args The arguments
 * @param services The additional services, which are added to the debugger session lookup.<br/>
 * See {@link #listen(com.sun.jdi.connect.ListeningConnector, java.util.Map, java.lang.Object[])} for a more detailed description of this argument.
 * @throws DebuggerStartException when {@link org.netbeans.api.debugger.DebuggerManager#startDebugging}
 * returns an empty array
 */
public static void startListening (
    ListeningConnector        connector,
    Map<String, ? extends Argument>  args,
    Object[]                  services
) throws DebuggerStartException {
    startListeningAndGetEngines(connector, args, services);
}
 
Example #28
Source File: Connectors.java    From openjdk-systemtest with Apache License 2.0 3 votes vote down vote up
public String getMapArguments(String arg, int i){
	
	Connector.Argument argument = (Connector.Argument)connectionSettings.get(i).get(arg);
	
	String result;
	
	if (argument == null) {
		result = "NULL";
	}
	result = argument.value();
	
	return result;
}
 
Example #29
Source File: JdiUtils.java    From java-svc with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Attaches to a dt_socket enabled JVM.
 * 
 * @param host
 *            the host to connect to.
 * @param port
 *            the port to connect to.
 * @return the {@link VirtualMachine} connected to.
 * @throws IOException
 * @throws IllegalConnectorArgumentsException
 */
public static VirtualMachine connect(String host, String port)
		throws IOException, IllegalConnectorArgumentsException {
	AttachingConnector socketConnector = getSocketConnector();
	Map<String, Argument> arguments = socketConnector.defaultArguments();
	arguments.get("hostname").setValue(host);
	arguments.get("port").setValue(port);
	return socketConnector.attach(arguments);
}
 
Example #30
Source File: AttachingDICookie.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * Returns map of arguments.
 *
 * @return map of arguments
 */
public Map<String,? extends Argument> getArgs () {
    return args;
}