Tip

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.