Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/connect In directory usw-pr-cvs1:/tmp/cvs-serv7476 Added Files: ArgumentImpl.java BooleanArgumentImpl.java IntegerArgumentImpl.java LaunchConnector.java SelectedArgumentImpl.java ShmemAttachConnector.java ShmemLaunchConnector.java ShmemListenConnector.java ShmemTransport.java SocketAttachConnector.java SocketLaunchConnector.java SocketListenConnector.java SocketTransport.java StringArgumentImpl.java Log Message: First version of Connectors. --- NEW FILE: ArgumentImpl.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.Connector; /** * Specification for and value of a Connector argument. Will always implement * a subinterface of ArgumentImpl: {@link StringArgumentImpl}, * {@link BooleanArgumentImpl}, {@link IntegerArgumentImpl}, * or {@link SelectedArgumentImpl}. * * @author Jan Stola */ public class ArgumentImpl implements Connector.Argument { /** Indicates whether this argument must be specified. */ protected boolean mandatory; /** Short human-readable label for this argument. */ protected String label; /** Human-readable description of this argument and its purpose. */ protected String description; /** Value of the argument. */ protected String value; /** * Short, unique identifier for the argument, not intended for * exposure to end-user. */ protected String name; /** * Creates new ArgumentImpl. * * @param mandatory indicates whether this argument must be specified. * @param label short human-readable label for this argument. * @param description human-readable description of this argument and its purpose. * @param name short, unique identifier for the argument, not intended for * exposure to end-user. */ ArgumentImpl(boolean mandatory, String label, String description, String name) { this.mandatory=mandatory; this.label=label; this.description=description; this.name=name; } /** * Indicates whether the argument must be specified. If <code>true</code>, * {@link #setValue(String)} must be used to set a non-<code>null</code> value * before using this argument in establishing a connection. * * @return <code>true</code> if the argument must be specified; <code>false</code> otherwise. */ public boolean isMandatory() { return mandatory; } /** * Returns a short human-readable label for this argument. * * @return a label for this argument */ public String label() { return label; } /** * Performs basic sanity check of argument. * * @return <code>true</code> if the value is valid to be used in {@link #setValue(String)} */ public boolean isValid(String value) { return (value!=null); } /** * Sets the value of the argument. The value should be checked with * {@link #isValid(String)} before setting it; invalid values will throw * an exception when the connection is established ({@link #connect} * method is called). */ public void setValue(String value) { this.value=value; } /** * Returns the current value of the argument. Initially, the default value * is returned. If the value is currently unspecified, <code>null</code> is returned. * * @return the current value of the argument. */ public String value() { return value; } /** * Returns a human-readable description of this argument and its purpose. * * @return the description of this argument */ public String description() { return description; } /** * Returns a short, unique identifier for the argument. Not intended for * exposure to end-user. * * @return the name of this argument. */ public String name() { return name; } } /* * $Log: ArgumentImpl.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: BooleanArgumentImpl.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.Connector; /** * Specification for and value of a Connector argument, whose value is * Boolean. * * @author Jan Stola */ public class BooleanArgumentImpl extends ArgumentImpl implements Connector.BooleanArgument { /** * Creates new BooleanArgumentImpl. * * @param mandatory indicates whether this argument must be specified. * @param label short human-readable label for this argument. * @param description human-readable description of this argument and its purpose. * @param name short, unique identifier for the argument, not intended for * exposure to end-user. */ BooleanArgumentImpl(boolean mandatory, String label, String description, String name) { super(mandatory, label, description, name); } /** * Performs basic sanity check of argument. * * @return <code>true</code> if value is a string representation of a boolean value. */ public boolean isValid(String value) { return ("true".equals(value)||"false".equals(value)); } /** * Sets the value of the argument. */ public void setValue(boolean value) { this.value=String.valueOf(value); } /** * Return the value of the argument as a boolean. Since the argument * may not have been set or may have an invalid value {@link #isValid(String)} * should be called on {@link ArgumentImpl#value()} to check its validity. * If it is invalid the boolean returned by this method is undefined. * * @return the value of the argument as a boolean. */ public boolean booleanValue() { return ("true".equals(value)); } } /* * $Log: BooleanArgumentImpl.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: IntegerArgumentImpl.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Specification for and value of a Connector argument, whose value is * an integer. Integer values are represented by their corresponding strings. * * @author Jan Stola */ public class IntegerArgumentImpl extends ArgumentImpl implements Connector.IntegerArgument { /** The lower bound for the value of this argument. */ protected int min; /** The upper bound for the value of this argument. */ protected int max; /** * Creates new IntegerArgumentImpl. * * @param mandatory indicates whether this argument must be specified. * @param label short human-readable label for this argument. * @param description human-readable description of this argument and its purpose. * @param name short, unique identifier for the argument, not intended for * exposure to end-user. * @param min the lower bound for the value of this argument. * @param max the upper bound for the value of this argument. */ IntegerArgumentImpl(boolean mandatory, String label, String description, String name, int min, int max) { super(mandatory, label, description, name); this.min=min; this.max=max; } /** * Sets the value of the argument. The value should be checked with * {@link #isValid(int)} before setting it; invalid values will throw * an exception when the connection is established ({@link #connect} * method is called). */ public void setValue(int value) { this.value=String.valueOf(value); } /** * Performs basic sanity check of argument. * * @return <code>true</code> if value represents an int that is * <code>min() <= value <= max()</code> */ public boolean isValid(String value) { int i; try { i=Integer.valueOf(value).intValue(); } catch (NumberFormatException e) { return false; } return isValid(i); } /** * Performs basic sanity check of argument. * * @return <code>true</code> if <code>min() <= value <= max()</code> */ public boolean isValid(int value) { return ((min()<=value) && (value<=max())); } /** * Return the value of the argument as a int. Since the argument may * not have been set or may have an invalid value {@link #isValid(String)} * should be called on {@link Connector.Argument#value()} to check its * validity. If it is invalid the int returned by this method is undefined. * * @return the value of the argument as a int. */ public int intValue() { try { return Integer.valueOf(value).intValue(); } catch (NumberFormatException e) { return 0; } } /** * The upper bound for the value. * * @return the maximum allowed value for this argument. */ public int max() { return max; } /** * The lower bound for the value. * * @return the minimum allowed value for this argument. */ public int min() { return min; } } /* * $Log: IntegerArgumentImpl.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: LaunchConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import java.util.Map; import java.util.List; import java.util.HashMap; import java.util.ArrayList; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Abstract super class for launching connectors. * * @author Jan Stola */ public abstract class LaunchConnector implements Connector { /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); Map args=new HashMap(); String sep=System.getProperty("file.separator"); Connector.Argument arg=new StringArgumentImpl(false, bundle.getString("Launcher"), bundle.getString("LauncherDesc"), "launcher"); arg.setValue(System.getProperty("java.home")+sep+"bin"+sep+"java"); args.put(arg.name(), arg); arg=new StringArgumentImpl(false, bundle.getString("Options"), bundle.getString("OptionsDesc"), "options"); arg.setValue(""); args.put(arg.name(), arg); arg=new StringArgumentImpl(true, bundle.getString("Class"), bundle.getString("ClassDesc"), "class"); arg.setValue(""); args.put(arg.name(), arg); arg=new StringArgumentImpl(false, bundle.getString("Arguments"), bundle.getString("ArgumentsDesc"), "arguments"); arg.setValue(""); args.put(arg.name(), arg); arg=new StringArgumentImpl(false, bundle.getString("Workdir"), bundle.getString("WorkdirDesc"), "workdir"); arg.setValue(System.getProperty("user.dir")); args.put(arg.name(), arg); arg=new StringArgumentImpl(false, bundle.getString("Quote"), bundle.getString("QuoteDesc"), "quote"); arg.setValue("\""); args.put(arg.name(), arg); //profiling args List choices=new ArrayList(4); choices.add("off"); choices.add("object"); choices.add("method"); choices.add("trace"); arg=new SelectedArgumentImpl(false, bundle.getString("AllocLevel"), bundle.getString("AllocLevelDesc"), "allocLevel", choices); arg.setValue("trace"); args.put(arg.name(), arg); arg=new BooleanArgumentImpl(false, bundle.getString("AllocThread"), bundle.getString("AllocThreadDesc"), "allocThread"); ((Connector.BooleanArgument)arg).setValue(true); args.put(arg.name(), arg); arg=new IntegerArgumentImpl(false, bundle.getString("AllocThraceDepth"), bundle.getString("AllocTraceDepthDesc"), "allocTraceDepth", 1, 100); ((Connector.IntegerArgument)arg).setValue(2); args.put(arg.name(), arg); choices=new ArrayList(3); choices.add("off"); choices.add("method"); choices.add("trace"); arg=new SelectedArgumentImpl(false, bundle.getString("CPULevel"), bundle.getString("CPULevelDesc"), "cpuLevel", choices); arg.setValue("trace"); args.put(arg.name(), arg); arg=new BooleanArgumentImpl(false, bundle.getString("CPUThread"), bundle.getString("CPUThreadDesc"), "cpuThread"); ((Connector.BooleanArgument)arg).setValue(true); args.put(arg.name(), arg); arg=new IntegerArgumentImpl(false, bundle.getString("CPUTraceDepth"), bundle.getString("CPUTraceDepthDesc"), "cpuTraceDepth", 1, 100); ((Connector.IntegerArgument)arg).setValue(2); args.put(arg.name(), arg); choices=new ArrayList(2); choices.add("exact"); choices.add("sampling"); arg=new SelectedArgumentImpl(false, bundle.getString("CPUMethod"), bundle.getString("CPUMethodDesc"), "cpuMethod", choices); arg.setValue("sampling"); args.put(arg.name(), arg); return args; } } /* * $Log: LaunchConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: SelectedArgumentImpl.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import java.util.List; import net.sourceforge.javaprofiler.jpi.connect.Connector; /** * Specification for and value of a Connector argument, whose value is * a String selected from a list of choices. * * @author Jan Stola */ public class SelectedArgumentImpl extends ArgumentImpl implements Connector.SelectedArgument { /** Possible values for the argument. */ protected List choices; /** * Creates new SelectedArgumentImpl. * * @param mandatory indicates whether this argument must be specified. * @param label short human-readable label for this argument. * @param description human-readable description of this argument and its purpose. * @param name short, unique identifier for the argument, not intended for * exposure to end-user. * @param choices possible values for the argument. */ SelectedArgumentImpl(boolean mandatory, String label, String description, String name, List choices) { super(mandatory, label, description, name); this.choices=choices; } /** * Return the possible values for the argument. * * @return List of String */ public List choices() { return choices; } /** * Performs basic sanity check of argument. * * @return <code>true</code> if value is one of {@link #choices()}. */ public boolean isValid(String value) { return choices.contains(value); } } /* * $Log: SelectedArgumentImpl.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: ShmemAttachConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import IProf; import CommunSetupShMem; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that attaches by shared memory to other VM. * * @author Jan Stola */ public class ShmemAttachConnector implements Connector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Attaches to VM using shared memory. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { ((ShmemTransport)transport()).initialize(); String address=null; Iterator iter=arguments.keySet().iterator(); while (iter.hasNext()) { Connector.Argument arg=(Connector.Argument)iter.next(); if ("address".equals(arg.name())) { String val=arg.value(); if ((val!=null)&&(val.length()!=0)) { address=val; } } } if (address!=null) { throw new IllegalConnectorArgumentsException("Wrong or missing shared memory area address.", "address"); } IProf prof=new IProf(new CommunSetupShMem(address, 256*1024)); prof.runClient(); //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return ShmemTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=new HashMap(1); Connector.Argument arg=new StringArgumentImpl(true, bundle.getString("Address"), bundle.getString("AttachAddress"), "address"); arg.setValue(""); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.ATTACHING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("ShmemAttachDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.ShmemAttachConnector"; } } /* * $Log: ShmemAttachConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: ShmemLaunchConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import java.util.Map; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that launches target VM using command line * and attaches to it through shared memory. * * @author Jan Stola */ public class ShmemLaunchConnector extends LaunchConnector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Launches the VM and connects to it through shared memory. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { ((ShmemTransport)transport()).initialize(); //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return ShmemTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=super.defaultArguments(); Connector.Argument arg=new StringArgumentImpl(false, bundle.getString("Address"), bundle.getString("LaunchAddress"), "address"); arg.setValue(""); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.LAUNCHING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("ShmemLaunchDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.ShmemLaunchConnector"; } } /* * $Log: ShmemLaunchConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: ShmemListenConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import IProf; import CommunSetupShMem; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that accepts shared memory connections initiated by other VMs. * * @author Jan Stola */ public class ShmemListenConnector implements Connector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Listens for connections initiated by other VMs. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { ((ShmemTransport)transport()).initialize(); String address=null; Iterator iter=arguments.keySet().iterator(); while (iter.hasNext()) { Connector.Argument arg=(Connector.Argument)iter.next(); if ("address".equals(arg.name())) { String val=arg.value(); if ((val!=null)&&(val.length()!=0)) { address=val; } } } if (address!=null) { throw new IllegalConnectorArgumentsException("Wrong or missing shared memory area address.", "address"); } IProf prof=new IProf(new CommunSetupShMem(address, 256*1024)); prof.runClient(); //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return SocketTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=new HashMap(1); Connector.Argument arg=new StringArgumentImpl(true, bundle.getString("Address"), bundle.getString("ListenAddress"), "address"); arg.setValue(""); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.LISTENING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("ShmemListenDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.ShmemListenConnector"; } } /* * $Log: ShmemListenConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: ShmemTransport.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.Transport; /** * Shared memory transport. * * @author Jan Stola */ public class ShmemTransport implements Transport { /** Name of this transport. */ private static final String name="net.sourceforge.javaprofiler.jpi.SharedMemoryTransport"; /** Singleton instance of this class. */ private static ShmemTransport instance; /** * Creates new SocketTransport. The constructor is private * because the class should be singleton. */ private ShmemTransport() { } /** * Initializes this transport. Loads the <code>pt_shmem</code> shared library * (<code>pt_shmem.dll</code> or <code>libpt_shmem.so</code>). */ protected void initialize() { System.loadLibrary("pt_shmem"); } /** * Returns singleton instance of this class. * * @return singleton instance of this class. */ public static ShmemTransport getDefault() { if (instance==null) { instance=new ShmemTransport(); } return instance; } /** * Returns a short identifier for the transport. Transport implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our transport implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". * * @return the name of this transport. */ public String name() { return name; } } /* * $Log: ShmemTransport.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: SocketAttachConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import IProf; import CommunSetupSocket; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that attaches by socket to other VM. * * @author Jan Stola */ public class SocketAttachConnector implements Connector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Attaches to VM using socket. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { String host="localhost"; int port=-1; Connector.Argument invalid=null; Iterator iter=arguments.keySet().iterator(); while (iter.hasNext()) { Connector.Argument arg=(Connector.Argument)iter.next(); if ("port".equals(arg.name())) { if (arg.isValid(arg.value())) { port=((Connector.IntegerArgument)arg).intValue(); } } if ("host".equals(arg.name())) { String val=arg.value(); if ((val!=null)&&(val.length()!=0)) { host=val; } } } if (port==-1) { throw new IllegalConnectorArgumentsException("Wrong or missing port number.", "port"); } IProf prof=new IProf(new CommunSetupSocket(CommunSetupSocket.CLIENT_MODE, host, port)); prof.runClient(); //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return SocketTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=new HashMap(2); Connector.Argument arg=new StringArgumentImpl(false, bundle.getString("Host"), bundle.getString("AttachHost"), "host"); arg.setValue(""); args.put(arg.name(), arg); arg=new IntegerArgumentImpl(true, bundle.getString("Port"), bundle.getString("AttachPort"), "port", 0, 65535); ((Connector.IntegerArgument)arg).setValue(0); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.ATTACHING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("SocketAttachDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.SocketAttachConnector"; } } /* * $Log: SocketAttachConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: SocketLaunchConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import java.util.Map; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that launches target VM using command line * and attaches to it through socket. * * @author Jan Stola */ public class SocketLaunchConnector extends LaunchConnector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Launches the VM and connects to it through socket. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return SocketTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=super.defaultArguments(); Connector.IntegerArgument arg=new IntegerArgumentImpl(false, bundle.getString("Port"), bundle.getString("LaunchPort"), "port", 0, 65535); arg.setValue(0); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.LAUNCHING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("SocketLaunchDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.SocketLaunchConnector"; } } /* * $Log: SocketLaunchConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: SocketListenConnector.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import IProf; import CommunSetupSocket; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import java.util.ResourceBundle; import net.sourceforge.javaprofiler.jpi.VirtualMachine; import net.sourceforge.javaprofiler.jpi.connect.*; /** * Connector that accepts socket connections initiated by other VMs. * * @author Jan Stola */ public class SocketListenConnector implements Connector { public static ResourceBundle bundle=ResourceBundle.getBundle("net.sourceforge.javaprofiler.jpiimpl.bundle"); /** * Listens for connections initiated by other VMs. */ public VirtualMachine connect(Map arguments) throws IllegalConnectorArgumentsException, ConnectingException { int port=-1; Connector.Argument invalid=null; Iterator iter=arguments.keySet().iterator(); while (iter.hasNext()) { Connector.Argument arg=(Connector.Argument)iter.next(); if ("port".equals(arg.name())) { if (arg.isValid(arg.value())) { port=((Connector.IntegerArgument)arg).intValue(); } } } if (port==-1) { throw new IllegalConnectorArgumentsException("Wrong or missing port number.", "port"); } IProf prof=new IProf(new CommunSetupSocket(CommunSetupSocket.SERVER_MODE, "localhost", port)); prof.runClient(); //PENDING return null; } /** * Returns the transport mechanism used by this connector to establish * connections with a target VM. * * @return the {@link Transport} used by this connector. */ public Transport transport() { return SocketTransport.getDefault(); } /** * Returns the arguments accepted by this Connector and their default values. * The keys of the returned map are string argument names. The values are * {@link Connector.Argument} containing information about the argument * and its default value. * * @return the map associating argument names with argument information * and default value. */ public Map defaultArguments() { Map args=new HashMap(1); Connector.IntegerArgument arg=new IntegerArgumentImpl(true, bundle.getString("Port"), bundle.getString("ListenPort"), "port", 0, 65535); arg.setValue(0); args.put(arg.name(), arg); return args; } /** * Returns a type of this connector. Three currently supported types are * attaching, listening and launching connectors. * * @return the type of this connector */ public int type() { return Connector.LISTENING_CONNECTOR; } /** * Returns a human-readable description of this connector and its purpose. * * @return the description of this connector */ public String description() { return bundle.getString("SocketListenDesc"); } /** * Returns a short identifier for the connector. Connector implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our connector implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". Not intended * for exposure to the end-user. * * @return the name of this connector. */ public String name() { return "net.sourceforge.javaprofiler.jpi.SocketListenConnector"; } } /* * $Log: SocketListenConnector.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: SocketTransport.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.Transport; /** * Socket transport. * * @author Jan Stola */ public class SocketTransport implements Transport { /** Name of this transport. */ private static final String name="net.sourceforge.javaprofiler.jpi.SocketTransport"; /** Singleton instance of this class. */ private static SocketTransport instance; /** * Creates new SocketTransport. The constructor is private * because the class should be singleton. */ private SocketTransport() { } /** * Returns singleton instance of this class. * * @return singleton instance of this class. */ public static SocketTransport getDefault() { if (instance==null) { instance=new SocketTransport(); } return instance; } /** * Returns a short identifier for the transport. Transport implementors * should follow similar naming conventions as are used with packages * to avoid name collisions. For example, our transport implementations * have names prefixed with "net.sourceforge.javaprofiler.jpi.". * * @return the name of this transport. */ public String name() { return name; } } /* * $Log: SocketTransport.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ --- NEW FILE: StringArgumentImpl.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developer of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; import net.sourceforge.javaprofiler.jpi.connect.Connector; /** * Specification for and value of a Connector argument, whose value * is a String. * * @author Jan Stola */ public class StringArgumentImpl extends ArgumentImpl implements Connector.StringArgument { /** * Creates new StringArgumentImpl. * * @param mandatory indicates whether this argument must be specified. * @param label short human-readable label for this argument. * @param description human-readable description of this argument and its purpose. * @param name short, unique identifier for the argument, not intended for * exposure to end-user. */ StringArgumentImpl(boolean mandatory, String label, String description, String name) { super(mandatory, label, description, name); } } /* * $Log: StringArgumentImpl.java,v $ * Revision 1.1 2001/08/22 13:35:31 stolis * First version of Connectors. * */ |