简体   繁体   English

如何使用Lotus Notes API从Java创建和运行代理

[英]How to create and run an agent from Java, using Lotus Notes API

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. 我创建了两个类,一个扩展了AgentBase ,另一个是普通的主类。 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: Agent类别:

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: Main类:

 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);

These 2 links are a good guide for you to go through. 这两个链接为您提供了很好的指导。 It should help you design java agents using eclipse. 它应该可以帮助您使用Eclipse设计Java代理。

ibm IBM

LekkimWorld LekkimWorld

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(). 您无需遍历代理集合以查找第一个代理-您可以使用GetAgent(“ agentname”),然后使用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 如果您的Java代码似乎正在查找代理并正在运行该代理,但是什么也没有发生,请检查服务器上的log.nsf数据库是否存在错误

You have defined two main entry points in your notes agent, however in the context of a notes agent, only NotesMain will execute. 您在Notes代理中定义了两个主要入口点,但是在Notes代理的上下文中,仅NotesMain将执行。 The static main method would only fire outside of the context of a notes agent, such as when running this in a 3rd party IDE such as Netbeans or Eclipse. 静态main方法仅会在Notes代理上下文之外触发,例如在NetBeans或Eclipse等第三方IDE中运行时。

For your code to run from the context of a Notes Agent, simply modify your NotesMain entry point to do all the work you need. 为了使代码从Notes代理的上下文中运行,只需修改NotesMain入口点即可完成所有需要的工作。

also.. what is that reference to sun.management.Agent for?? 还..那对sun.management.Agent的引用是什么?

import lotus.domino.*;
import java.util.Vector;

public class AnAgent extends AgentBase {

  public void NotesMain() {
     private Session m_session;
     private AgentContext m_agentContext;
     private Database m_db;

    try {

      m_session = getSession();
      m_agentContext =  m_session.getAgentContext();

      // (Your code goes here) 
      System.out.println("I am an agent");
      m_db = m_session.getDatabase("","LotusDB2.nsf");

       if(m_db.isOpen())
            System.out.println("database open");
            Vector agents = m_db.getAgents();

            if(agents != null && 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);
                    // whatever it is you are trying to do here...
                }
            }

    } catch(Exception e) {

      e.printStackTrace();

    }

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM