⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agentlauncherexploreritem.java

📁 一个agent 工具包,可以开发移动设备应用,考虑了安全措施
💻 JAVA
字号:
package SOMA.agent;

import java.util.*;
import java.io.*;

import SOMA.explorer.*;
import SOMA.Environment;

/** Voce di menu per gestire il lancio di agenti...
* @author Livio Profiri
*/

public class AgentLauncherExplorerItem extends ExplorerItem
{
  Environment env;

  public static final String SYSTEM_CLASSLOADER = "-s";
  public static final String NOT_TRACEABLE = "-nt";
  public static final String NO_START = "-ns";

  public AgentLauncherExplorerItem( Environment env )
  {
    super( "[" + SYSTEM_CLASSLOADER + "] [" + NOT_TRACEABLE + "] [" + NO_START +
           "] \"Agent ID\" { \"Arg1\" \"Arg2\" ... }" );
    this.env = env;
    System.out.println("AgentLauncher begin");
  }

  public Object Execute( Collection Parameters, PrintStream out )
  {
    HashSet options = new HashSet();

    Iterator i = Parameters.iterator();

    while( i.hasNext() )
    {
      String option = (String)i.next();

      out.println( option );
      if( option.startsWith( "-" ) )
      {
        i.remove(); // Rimuove il parametro dalla lista dei parametri.
        options.add( option );
      }
      else
        break;
    }

    i = Parameters.iterator();
    if( i.hasNext() )
    {
      String agentName = (String)i.next();
      i.remove();
      out.println( "Agent class: " + agentName );

      int NumParameters = Parameters.size();
      String[] ParametersArray = new String[NumParameters];

      out.println( "Creating agent: " + agentName + " Parameters: " );
      for( int j = 0; j < NumParameters; j++ )
      {
        ParametersArray[j] = (String)i.next();
        out.println( "  " + j + ")  " + ParametersArray[j] );
      }

      if( options.contains( SYSTEM_CLASSLOADER ) )
        out.println( SYSTEM_CLASSLOADER + " ==> Using System ClassLoader." );

      if( options.contains( NOT_TRACEABLE ) )
        out.println( NOT_TRACEABLE + " ==> Not Traceable agent." );

      if( options.contains( NO_START ) )
        out.println( NO_START + " ==> No Start: the agent will not be started." );

      // true --> System agent!
      AgentWorker worker =
           env.agentManager.createAgent( agentName, ParametersArray,
                                         options.contains( SYSTEM_CLASSLOADER ),
                                         !options.contains( NOT_TRACEABLE ) );

      if( worker == null )
        out.println( "ERROR: can't create agent." );
      else
      {
        if( options.contains( NO_START ) )
          out.println( "Worker: " + worker + " created, but not started." );
        else
        {
          try
          {
            worker.start();
          }
          catch( Exception e )
          {
            e.printStackTrace( out );
          }
          out.println( "Worker: " + worker + " created and started." );
        }
      }

      return worker;
    }

    out.println( "Invalid parameters." );

    return null;
  }

  public String Help( PrintStream out )
  {
    out.println();
    out.println( "Launch an agent with the specified options " );
    out.println( "  and parameters: " + toString() );
    out.println();
    out.println( "\"agent ID\" --> Agent class name (no .class suffix)." );
    out.println();
    out.println( "{ \"Arg1\" \"Arg2\" ... } --> Optional arguments. They will be passed in a " );
    out.println( "     String[] to Agent.putArgument( Object obj )." );
    out.println();
    out.println( SYSTEM_CLASSLOADER + " --> Use System ClassLoader. The agent will use the default" );
    out.println( "     Java security protection mechanisms" );
    out.println();
    out.println( NOT_TRACEABLE + " --> Not Traceable agent. The agent will not be traceable and " );
    out.println( "     he will not have a Mailbox to receive messages." );
    out.println();
    out.println( NO_START + " ==> No Start: the agent will not be started. It is possible to " );
    out.println( "     move the agent to another place (Worker.go(...)) or to start it later." );
    out.println();

    return getSyntax();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -