1 13 package org.eclipse.jdi.internal.connect; 14 15 16 import java.io.IOException ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.eclipse.jdi.internal.VirtualMachineManagerImpl; 21 22 import com.sun.jdi.VirtualMachine; 23 import com.sun.jdi.connect.IllegalConnectorArgumentsException; 24 import com.sun.jdi.connect.ListeningConnector; 25 26 27 public class SocketListeningConnectorImpl extends ConnectorImpl implements ListeningConnector { 28 29 private int fPort; 30 31 private int fTimeout; 32 33 34 37 public SocketListeningConnectorImpl(VirtualMachineManagerImpl virtualMachineManager) { 38 super(virtualMachineManager); 39 40 SocketTransportImpl transport = new SocketTransportImpl(); 42 setTransport(transport); 43 } 44 45 48 public Map defaultArguments() { 49 HashMap arguments = new HashMap (1); 50 51 IntegerArgumentImpl intArg = new IntegerArgumentImpl("port", ConnectMessages.SocketListeningConnectorImpl_Port_number_at_which_to_listen_for_VM_connections_1, ConnectMessages.SocketListeningConnectorImpl_Port_2, true, SocketTransportImpl.MIN_PORTNR, SocketTransportImpl.MAX_PORTNR); arguments.put(intArg.name(), intArg); 54 55 intArg = new IntegerArgumentImpl("timeout", ConnectMessages.SocketListeningConnectorImpl_Timeout_before_accept_returns_3, ConnectMessages.SocketListeningConnectorImpl_Timeout_4, false, 0, Integer.MAX_VALUE); arguments.put(intArg.name(), intArg); 58 59 return arguments; 60 } 61 62 65 public String name() { 66 return "com.sun.jdi.SocketListen"; } 68 69 72 public String description() { 73 return ConnectMessages.SocketListeningConnectorImpl_Accepts_socket_connections_initiated_by_other_VMs_5; 74 } 75 76 79 private void getConnectionArguments(Map connectionArgs) throws IllegalConnectorArgumentsException { 80 String attribute = "port"; try { 82 IntegerArgument argument = (IntegerArgument) connectionArgs.get(attribute); 84 if (argument != null && argument.value() != null) { 85 fPort = argument.intValue(); 86 } else { 87 fPort = 0; 88 } 89 attribute = "timeout"; argument = (IntegerArgument) connectionArgs.get(attribute); 93 if (argument != null && argument.value() != null) { 94 fTimeout = argument.intValue(); 95 } else { 96 fTimeout = 0; 97 } 98 } catch (ClassCastException e) { 99 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketListeningConnectorImpl_Connection_argument_is_not_of_the_right_type_6, attribute); 100 } catch (NullPointerException e) { 101 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketListeningConnectorImpl_Necessary_connection_argument_is_null_7, attribute); 102 } catch (NumberFormatException e) { 103 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketListeningConnectorImpl_Connection_argument_is_not_a_number_8, attribute); 104 } 105 } 106 107 111 public String startListening(Map connectionArgs) throws IOException , IllegalConnectorArgumentsException { 112 getConnectionArguments(connectionArgs); 113 String result = null; 114 try { 115 result = ((SocketTransportImpl)fTransport).startListening(fPort); 116 } catch (IllegalArgumentException e) { 117 throw new IllegalConnectorArgumentsException(ConnectMessages.SocketListeningConnectorImpl_ListeningConnector_Socket_Port, "port"); } 119 return result; 120 } 121 122 125 public void stopListening(Map connectionArgs) throws IOException { 126 ((SocketTransportImpl)fTransport).stopListening(); 127 } 128 129 133 public VirtualMachine accept(Map connectionArgs) throws IOException , IllegalConnectorArgumentsException { 134 getConnectionArguments(connectionArgs); 135 SocketConnection connection = (SocketConnection) ((SocketTransportImpl)fTransport).accept(fTimeout, 0); 136 return establishedConnection(connection); 137 } 138 139 142 public boolean supportsMultipleConnections() { 143 return true; 144 } 145 146 149 public int listeningPort() { 150 return fPort; 151 } 152 } 153 | Popular Tags |