FileDocCategorySizeDatePackage
MyPersistentClass.javaAPI DocExample4387Wed Apr 19 11:20:24 BST 2000examples.activation

MyPersistentClass

public class MyPersistentClass extends Activatable implements examples.activation.YetAnotherRemoteInterface

Fields Summary
private Vector
transactions
private File
holder
Constructors Summary
public MyPersistentClass(ActivationID id, MarshalledObject data)


	super(id, 0);

        // Extract the File object from the MarshalledObject that was 
        // passed to the constructor 
	//
	holder = (File)data.get();

	if (holder.exists()) {
	    // Use the MarshalledObject to restore my state
	    //
	    this.restoreState();
	} else {
	    transactions = new Vector(1,1);
	    transactions.addElement("Initializing transaction vector");
	}
    
Methods Summary
public java.util.VectorcalltheServer(java.util.Vector v)


	int limit = v.size();
	for (int i = 0; i < limit; i++) {
	    transactions.addElement(v.elementAt(i));
	}

	// Save this object's data out to file
	//
	this.saveState();
	return transactions;
    
public java.util.VectorgetTransactions()

	return transactions;
    
private voidrestoreState()

	File f = holder;
	FileInputStream fis = new FileInputStream(f);
        ObjectInputStream ois = new ObjectInputStream(fis);
        transactions = (Vector)ois.readObject();
        ois.close();
    
private voidsaveState()


        FileOutputStream fos = null;
        ObjectOutputStream oos = null;

	try {
	    File f  = holder;
		try {
	            fos = new FileOutputStream(f);
		} catch (IOException e1) {
		    e1.printStackTrace(); 
	            throw new RuntimeException("Error creating FileOutputStream");
		}
		try {
	            oos = new ObjectOutputStream(fos);
		} catch (IOException e2) {
	            throw new RuntimeException("Error creating ObjectOutputStream");
		}
		try {
	            oos.writeObject(getTransactions());
		} catch (IOException e3) {
	            throw new RuntimeException("Error writing Vector");
		}
		try {
	            oos.close();
		} catch (IOException e3) {
	            throw new RuntimeException("Error closing stream");
		}

	} catch (SecurityException e4) {
	    throw new RuntimeException("Security Problem");
	} catch (Exception e) {
	    throw new RuntimeException("Error saving vector of data");
	}