Domino Task in Java

Replace the old fashion C Code server task with JAVA and enjoy portability. Some comments are in French but I am

sure you will enjoy it!

To load: load runjava JavaPwer (case sensitive).
Just use Tell JavaPower Help, Tell JavaPower Quit, Tell JavaPower VERIFIER busytime.nsf on your Domino console (do not forget to let LOG=log.nsf,1 in your ini file.

import lotus.domino.*;
import lotus.notes.addins.JavaServerAddin;
import lotus.notes.internal.MessageQueue;
import java.util.*;

public class JavaPower extends JavaServerAddin
{
      int noTache; // ID of the Task
      static JavaPower javaPower;
      Vector vector; // Addin info

      // Message Queue
      int erreur; // to manage errors
      String lemsg = MSG_Q_PREFIX + "JAVAPOWER"; // MQ$ convention C de Lotus
      // In UpperCase please
      StringBuffer args = new StringBuffer(); // tell args
      int longueur = 256;// tell command length

      MessageQueue messageQueue;

      // dummy const
      public static final int CMD_EXEC=1;
      public static final int CMD_HELP=0;
      public static final int CMD_ERR=-1;

      // Pure Notes to do something!
      Session session;
      Database database;

      private void afficheMessageNormal(String chaine)
      {
        AddInLogMessageText(chaine, NOERROR);
        AddInIdle();
      }

      public static void main(String[] argv)
      {
        javaPower = new JavaPower() ;
        javaPower.start() ;
      }

      public void JavaPower()
      {
        setName("JavaPower");
      }

      private void afficheHelp()
      {
        afficheMessageNormal("Java Power mode d'emploi");
        afficheMessageNormal("Usage: ");
        afficheMessageNormal("Help             : ces lignes d'aide");
        afficheMessageNormal("VERIFIER base.nsf: base existe?");
        afficheMessageNormal("QUIT ou EXIT     : permet de fermer le programme");
      }

      private boolean verifieNotes(String nomBase)
      {
        boolean retour=false;

        try
        {
            session = NotesFactory.createSession();
            database = session.getDatabase("",nomBase);
            if (database.isOpen())
            {
              retour = true;
            }
            else
            {
              afficheMessageNormal("Java Power: Impossible d'ouvrir la base " + nomBase);
            }
        }
        catch (NotesException e)
        {
          afficheMessageNormal("Java Power: Erreur Notes=" + e.getMessage());
        }
        return retour;
      }

      private void purgeNotes()
      {
        try
        {
            database.recycle();
            session.recycle();
        }
        catch (NotesException e)
        {
          afficheMessageNormal("Java Power: Erreur Notes=" + e.getMessage());
        }
      }

      private int analyseMsg(StringBuffer param)
      {
        int retour = CMD_ERR;
        int nbParam;

        StringTokenizer st;
        st = new StringTokenizer(args.toString());
        nbParam = st.countTokens();

        if (nbParam==1)
        {
          // 1 seul param, donc HELP sinon return false!
          // On s'en fiche, si un param aide pour l'instant
          afficheHelp(); // Show HELP!
          retour = CMD_HELP;
        }
        if (nbParam==2)
        {
            String s = st.nextToken();
            if (s.equalsIgnoreCase("VERIFIER"))
            {
              retour=CMD_EXEC;
              if (!verifieNotes(st.nextToken()))
              {
                retour= CMD_ERR;
                purgeNotes();
              }
            }
            else
            {
              afficheHelp();
              retour = CMD_HELP;
            }
        }
        if (nbParam>2)
        {
          // impossible
          afficheHelp();
          retour = CMD_HELP;

        }


        return retour;
      }

      public void runNotes()
      {

        OSPreemptOccasionally();
        noTache = AddInCreateStatusLine("Java Power"); // Espace esthetique
        AddInSetStatusText("Initialisation de Java Power");
        AddInSetStatusLine(noTache, "Initialisation en cours....");

        // Init Queue des messages
        // Etape 1, on cree la file des messages
        messageQueue = new MessageQueue(); // Instancions

        AddInSetStatusLine(noTache, "Idle"); // restons coherent avec Notes!
        erreur = messageQueue.create(lemsg,0,0); // Pas de limite

        if (erreur!= NOERROR)
        {
          /* Commentaire! Already loaded, stop!
            // S'il y a une erreur de creation de file des messages
          C'est que la file existe deja
            // Donc que la tache est deja demarree CQFD!
          Fin du commentaire

          */
          afficheMessageNormal("Java Power: programme deja charge, abandon...");
        }
        else
        {
          afficheMessageNormal("Java Power: Attente de vos instructions");

          // Etape 2 on ouvre
          erreur = messageQueue.open(lemsg,0); // 1 si a creer, 0 si non
          if (erreur!= NOERROR)
          {
            afficheMessageNormal("Java Power: Impossible d'ouvrir la ligne des msg!");
          }
          else
          {
                afficheMessageNormal("Java Power: Attente de vos instructions...");
                while (NOERROR == erreur)
                {
                  erreur = messageQueue.get(args,longueur,
                                            messageQueue.MQ_WAIT_FOR_MSG,0);
                  if (NOERROR == erreur)
                  {
                    int retour;
                    retour = analyseMsg(args);
                    if (retour == CMD_EXEC)
                    {
                        AddInSetStatusLine(noTache,"Java Power: Execution en cours...");
                        // Faire quelque chose d'interessant!
                        System.err.println("Ben on va faire quelque chose!");
                        AddInSetStatusLine(noTache, "Idle");
                    } // Fin if retour==CMD_EXEC

                    AddInIdle();
                    // Forcer car SHOW TASKS envoit un parametre non traite par
                    // notre tache!
                    erreur = NOERROR;
                  } // Fin if erreur==NOERROR
                } // Fin while
            } // Fin else pb ligne des msg
            // Si on arrive la, c'est que l'on doit quitter!
            AddInSetStatusText("Fin de la tache");
            AddInLogMessageText("Java Power: GoodBye!", NOERROR);
            AddInDeleteStatusLine( noTache );
            // File d'attente!
            erreur = messageQueue.close(0);
            //fin file attente!
        } // Fin else boucle des msg
    } // fin runNotes
}
This was first published in April 2001

Dig deeper on Java for Lotus Notes Domino

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.uk

Close