< prev index next >

## src/com/sun/javatest/agent/AgentMain.java

Print this page

     357         }
     358
     359         if (!Agent.isValidConcurrency(concurrency)) {
     360             throw new BadArgs("Bad value for concurrency: " + concurrency);
     361         }
     362     }
     363
     364     /**
     365      * Create a connection factory based on the values decoded by decodeAllArgs
     366      * Normally called from createAgent.
     367      * @return a connection factory based on the values decoded by decodeAllArgs
     368      * @throws AgentMain.Fault if there is a problem createing the factory
     369      */
     370     protected ConnectionFactory createConnectionFactory() throws Fault {
     371         String s = AgentMain.class.getName();
     372         String pkg = s.substring(0, s.lastIndexOf('.'));
     373
     374         switch (mode) {
     375         case ACTIVE:
     376             try {
     377                 Class c = Class.forName(pkg + ".ActiveConnectionFactory");
     378                 Constructor m = c.getConstructor(new Class[] {String.class, int.class});
     379                 Object[] args = { activeHost, new Integer(activePort) };
     380                 return (ConnectionFactory)(m.newInstance(args));
     381             }
     382             catch (Throwable e) {
     383                 Throwable t = unwrapInvocationTargetException(e);
     384                 String[] msgs = {
     385                     "Error occurred while trying to start an active agent",
     386                     t.toString(),
     387                     "Are the java.net classes available?"
     388                 };
     389                 throw new Fault(msgs);
     390             }
     391
     392         case PASSIVE:
     393             try {
     394                 Class c = Class.forName(pkg + ".PassiveConnectionFactory");
     395                 Constructor m = c.getConstructor(new Class[] {int.class, int.class});
     396                 Object[] args = { new Integer(passivePort), new Integer(concurrency + 1) };
     397                 return (ConnectionFactory)(m.newInstance(args));
     398             }
     399             catch (Throwable e) {
     400                 Throwable t = unwrapInvocationTargetException(e);
     401                 if (t instanceof IOException)
     402                     throw new Fault("Cannot create socket on port " + passivePort);
     403                 else {
     404                     String[] msgs = {
     405                         "Error occurred while trying to start a passive agent",
     406                         t.toString(),
     407                         "Are the java.net classes available?"
     408                     };
     409                     throw new Fault(msgs);
     410                 }
     411             }
     412
     413         case SERIAL:
     414             try {
     415                 Class c = Class.forName(pkg + ".SerialPortConnectionFactory");
     416                 Constructor m = c.getConstructor(new Class[] {String.class, String.class, int.class});
     417                 Object[] args = {serialPort, Agent.productName, new Integer(10*1000)};
     418                 return (ConnectionFactory)(m.newInstance(args));
     419             }
     420             catch (InvocationTargetException e) {
     421                 Throwable t = e.getTargetException();
     422                 if (t instanceof IllegalArgumentException ||
     423                     t.getClass().getName().equals("gnu.io.NoSuchPortException")) {
     424                     throw new Fault(serialPort + " is not a valid port");
     425                 }
     426                 else {
     427                     String[] msgs = {
     428                         "Error occurred while trying to access the communication ports",
     429                         t.toString(),
     430                         "Is the gnu.io extension installed?"
     431                     };
     432                     throw new Fault(msgs);
     433                 }
     434             }
     435             catch (Throwable e) {
     357         }
     358
     359         if (!Agent.isValidConcurrency(concurrency)) {
     360             throw new BadArgs("Bad value for concurrency: " + concurrency);
     361         }
     362     }
     363
     364     /**
     365      * Create a connection factory based on the values decoded by decodeAllArgs
     366      * Normally called from createAgent.
     367      * @return a connection factory based on the values decoded by decodeAllArgs
     368      * @throws AgentMain.Fault if there is a problem createing the factory
     369      */
     370     protected ConnectionFactory createConnectionFactory() throws Fault {
     371         String s = AgentMain.class.getName();
     372         String pkg = s.substring(0, s.lastIndexOf('.'));
     373
     374         switch (mode) {
     375         case ACTIVE:
     376             try {
     377                 Class<?> c = Class.forName(pkg + ".ActiveConnectionFactory");
     378                 Constructor m = c.getConstructor(new Class[] {String.class, int.class});
     379                 Object[] args = { activeHost, new Integer(activePort) };
     380                 return (ConnectionFactory)(m.newInstance(args));
     381             }
     382             catch (Throwable e) {
     383                 Throwable t = unwrapInvocationTargetException(e);
     384                 String[] msgs = {
     385                     "Error occurred while trying to start an active agent",
     386                     t.toString(),
     387                     "Are the java.net classes available?"
     388                 };
     389                 throw new Fault(msgs);
     390             }
     391
     392         case PASSIVE:
     393             try {
     394                 Class<?> c = Class.forName(pkg + ".PassiveConnectionFactory");
     395                 Constructor m = c.getConstructor(new Class[] {int.class, int.class});
     396                 Object[] args = { new Integer(passivePort), new Integer(concurrency + 1) };
     397                 return (ConnectionFactory)(m.newInstance(args));
     398             }
     399             catch (Throwable e) {
     400                 Throwable t = unwrapInvocationTargetException(e);
     401                 if (t instanceof IOException)
     402                     throw new Fault("Cannot create socket on port " + passivePort);
     403                 else {
     404                     String[] msgs = {
     405                         "Error occurred while trying to start a passive agent",
     406                         t.toString(),
     407                         "Are the java.net classes available?"
     408                     };
     409                     throw new Fault(msgs);
     410                 }
     411             }
     412
     413         case SERIAL:
     414             try {
     415                 Class<?> c = Class.forName(pkg + ".SerialPortConnectionFactory");
     416                 Constructor m = c.getConstructor(new Class[] {String.class, String.class, int.class});
     417                 Object[] args = {serialPort, Agent.productName, new Integer(10*1000)};
     418                 return (ConnectionFactory)(m.newInstance(args));
     419             }
     420             catch (InvocationTargetException e) {
     421                 Throwable t = e.getTargetException();
     422                 if (t instanceof IllegalArgumentException ||
     423                     t.getClass().getName().equals("gnu.io.NoSuchPortException")) {
     424                     throw new Fault(serialPort + " is not a valid port");
     425                 }
     426                 else {
     427                     String[] msgs = {
     428                         "Error occurred while trying to access the communication ports",
     429                         t.toString(),
     430                         "Is the gnu.io extension installed?"
     431                     };
     432                     throw new Fault(msgs);
     433                 }
     434             }
     435             catch (Throwable e) {

< prev index next >