views:

125

answers:

2

I am trying to create an agent and run it!! I have created two classes, one extends AgentBase . and the other one is a normal main class. I have written the code for agent in the 1st class and trying to run it from the second class. But i am not able to access it. I am a complete novice here, any guidance would be appreciated.

Agent Class

import lotus.domino.*;

import java.util.Vector;
import sun.management.Agent;

public class anagent extends AgentBase {

  public void NotesMain() {

    try {

      Session session = getSession();

      AgentContext agentContext = 

          session.getAgentContext();

      // (Your code goes here) 


      System.out.println

      ("I am an agent");

    } catch(Exception e) {

      e.printStackTrace();

    }

  }

Main Class

public static void main(String [] args) throws NotesException {

Session session = null;
Database db = null;
      try {
        session =  NotesFactory.createSession(hostname,UserName, password);
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    boolean x = session.isValid();
    System.out.println("success- "+x);

    try {
        db = session.getDatabase(null,"LotusDB2.nsf");
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if(db.isOpen())
    System.out.println("database open");



        //Agent agnt = (Agent) a.firstElement();
    //agnt.toString();}
     //AgentContext agentContext = session.getAgentContext();
      // db = agentContext.getCurrentDatabase();
       Vector agents = db.getAgents();
       //lotus.domino.Agent agent = new lotus.domino.Agent();
       System.out.println("Agents in database:");
       if(agents.size()>0) System.out.println("some agents found");
       for (int i=0; i<agents.size(); i++)

       {

         lotus.domino.Agent agent = (lotus.domino.Agent)agents.elementAt(i);
+1  A: 

These 2 links are a good guide for you to go through. It should help you design java agents using eclipse.

ibm

LekkimWorld

giulio
thanx.. good links
Nitin Garg
+1  A: 

When you say you cannot access the agent, are you getting an error? You do not need to loop through the agent collection looking for the first agent - you can use GetAgent("agentname") and then Agent.run(). If your Java code seems to be finding the agent and running it, but nothing happens, check the log.nsf database on your server for possible errors

Ed Schembor
hey thanx for replymy problem matches with http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/052ce2e1d94ac7b9852571870037a86a?OpenDocumentright now, i am following the solution suggested there!!
Nitin Garg