Listing 1. PrinterImplActivatable.java

import java.rmi.*;
import java.rmi.activation.*;
import java.util.*;
import java.io.*;

public class PrinterImplActivatable extends Activatable implements PrinterInterface{

int jobs=0;                //counting the printer jobs
private File storage=null; //the file for storing the initialization information 

//defining the activation/reactivation constructor for the activable remote object 
– this //constructor is called by the rmid
 public PrinterImplActivatable(ActivationID id,MarshalledObject data)
     throws RemoteException
       {
       super(id,0);
       try{
          //get the de-serialize form of the object
          storage=(File)data.get();

          //verify if the file exists
          if(storage.exists())
           {
           //the file exists -> initialization of the object
           this.restoreObject();
           }else{
                //the file doesn’t exists -> manually initialization
                jobs=0;
                }
            }catch(IOException e)
              {System.out.println(e.getMessage());
            }catch(java.lang.ClassNotFoundException e)
              {System.out.println(e.getMessage());}    
       }

private void restoreObject()
      {
	File F=storage;
	try
        {
	  FileInputStream FIS=new FileInputStream(F);
        ObjectInputStream OIS=new ObjectInputStream(FIS);
        jobs=(Integer)OIS.readObject();
        OIS.close();
	  }catch(IOException e)
           {System.out.println(e.getMessage());
        }catch(ClassNotFoundException e)
           {System.out.println(e.getMessage());}        
 }

    private synchronized void saveObject()
        {
        FileOutputStream FOS=null;
        ObjectOutputStream OOS=null;

	    File F=storage;
	    try
            {
	  	FOS=new FileOutputStream(F);
		OOS=new ObjectOutputStream(FOS);		
	    	OOS.writeObject(jobs);
		OOS.close();
	      }catch(IOException e)
              {System.out.println(e.getMessage());}
   }
  
//setPrinterJob method
public void setPrinterJob()throws RemoteException{
  jobs++;
  //upgrade the file content
  this.saveObject();
  }

// removePrinterJob
public void removePrinterJob()throws RemoteException{
  if(jobs>0)
       {       
       jobs--;
       //upgrade the file content
       this.saveObject();
       }
  }

//getPrinterJobsNumber
public int getPrinterJobsNumber()
    {
    return jobs;
    }  
}  

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.