Home > Domino Tips > Developer > Java > Domino Task in Java
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

Domino Task in Java


Jerome Deniau
04.16.2001
Rating: -3.06- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.

Code

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
}

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Java
Java code inserts data from Notes documents into a SQL table
Java code shortens strings in a SQL table
How to execute a stored procedure in Lotus Notes Domino using Java
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts