Package ch.ethz.inf.net

Examples of ch.ethz.inf.net.WebServer



  public static void main(String[] args) {
    int exitCode=1; // assume there will be an error

    WebServer server=WebServer.allowRMIPeersToRetrieveByteCode();

    String insertId    = System.getProperty("insertId",null);
    String remoteProse = System.getProperty("prose.address","NONE");
    String aspectToInsert = System.getProperty("insert","NONE");
    String aspectToWithdraw=System.getProperty("withdraw","NONE");
    String transactionId=System.getProperty("txId",null);
    String finishTxAction=System.getProperty("finishtx","NONE");
    String list=System.getProperty("list","NONE");

    try {
      String host  = null;
      int port = -1;
      try  {
        host = remoteProse.substring(0,remoteProse.indexOf(':'));
        String portName = remoteProse.substring(remoteProse.indexOf(':') +1, remoteProse.length());
        port = Integer.parseInt(portName);
      }
      catch (java.lang.StringIndexOutOfBoundsException e)  {
        throw new java.net.MalformedURLException("Missing ':' separator");
      }
      catch (java.lang.NumberFormatException e) {
        throw new java.net.MalformedURLException("Illegal port number");
      }

      String instance = System.getProperty("prose.instance");

      RemoteAspectManager bothRams[] = RemoteProseComponent.doGetRemoteAspectManagers(host,port);
      RemoteAspectManager ram = null;

      if ("activeInstance".equals(instance))
        ram = bothRams[0];
      else if ("testInstance".equals(instance))
        ram = bothRams[1];
      else
        throw new Error("instance must be specified by script!");

      if ("NONE".equals(remoteProse))  {
        System.err.println("no host:port specified");
        usage();
        System.exit(1);
      }

      if ("commit".equals(finishTxAction)) {
        if (transactionId == null)
          throw new IllegalArgumentException("transaction id must be specified");

        ram.commit(transactionId);
      }

      if ("abort".equals(finishTxAction)) {
        if (transactionId == null)
          throw new IllegalArgumentException("transaction id must be specified");

        ram.abort(transactionId);
      }

      if ( !("NONE".equals(aspectToInsert))) {
        // we have to insert an aspect
        // assumption : no constructor
        Class cls = Class.forName(aspectToInsert);
        Aspect aspect = (Aspect)cls.newInstance();
        if (insertId != null)
          aspect.associateTo(insertId);

        // obtain remote prose reference
        if (transactionId == null)
          ram.insert(aspect);
        else
          ram.insert(aspect,transactionId);
      }

      if ( !("NONE".equals(aspectToWithdraw)) ) {
        Object[] array=ram.allAspects().toArray();
        int withdrawIdx = Integer.parseInt(aspectToWithdraw);
        if (transactionId == null)
          ram.withdraw((AspectSurrogate)array[withdrawIdx]);
        else
          ram.withdraw((AspectSurrogate)array[withdrawIdx],transactionId);
      }

      if ( !("NONE".equals(list)) ) {
        Object[] array=ram.allAspects().toArray();
        for (int i = 0; i < array.length; i++)
          System.err.println("Aspect[" + i + "]: " + array[i]);
      }
      server.stop();
      exitCode =0;
    }
    catch (java.lang.ClassNotFoundException cannotFoundClass) {
      System.err.println("prose: *Error* The class '" + aspectToInsert + "' could not be found in the classpath");
    }
    catch (java.lang.IllegalAccessException cannotCallConstructor) {
      System.err.println("prose: *Error* The class " + aspectToInsert + "' cannot be instantiated. Please check"+
      "               that the constructor (paramterless) has the correct access rights");
    }
    catch (java.net.UnknownHostException wrongHostName) {
      System.err.println("prose: *Error* The prose service you specified does not exist at " + remoteProse);
    }
    catch (java.rmi.ConnectException serverNotThere) {
      System.err.println("prose: *Error* The prose service you specified does not exist at " + remoteProse);
    }
    catch (java.lang.InstantiationException cannotCreateAspect) {
      System.err.println("prose: *Error* The aspect class you specified (" + aspectToInsert + ") " +
      " cannot be instantiated");
    }
    catch (java.rmi.RemoteException cannotConnect) {
      System.err.println("prose: *Error* The following exception occured while trying to connect to"+
          "               the service " + cannotConnect+ ":\n");
    }
    catch (java.net.MalformedURLException shitFromUser) {
      System.err.println("prose: *Error* The address you specified does not have the format <host>:<port>");
    }
    catch (java.lang.IllegalArgumentException missingArgs) {
      System.err.println("prose: *Error* " + missingArgs.getMessage());
    }
    catch (java.io.IOException cannotTalkToRemoteProse) {
      System.err.println("prose: *Error* " + cannotTalkToRemoteProse.getMessage());
    }
    finally {
      server.stop();
    }
    System.exit(exitCode);
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.net.WebServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.