Publish ver 1.13

(simple object database)



    This is an object publishing system. Publish allows you to save/restore your java objects on the server.  Each object will be saved under some unique name. Later you can read (restore) those objects from the server.
    The system contains two parts: clients class Publish and servlet. Why we are using servlet here ? Because we post classes to server. We will make sure our application will be free from the firewall's restrictions.
    So, your clients application can communicate with PublishServlet for saving/restoring objects.
    The saved class should implements serializable interface (it is a Java requrements).

the interface itself is primitive:

public Publish (String host_with_publish_servlet, String directory_for_classes_store)
Constructor. Create new Publish adaptor. The second parameter sets server directory for saved classes.  For example . is a root directory for your servletrunner.

public String putObject(Object obj) throws IOException
saved the given object. Returns server's object name

public String putObject(Object obj, String name) throws IOException
saved the given object under that name. Returns server's object name

public Object getObject (String name_of_the_object) throws IOException
returns object with the given name or null if such object does not exist on the server

public Vector getObjects(String name_of_the_class) throws IOException
returns Vector of objects with the given class name

public Vector getObjects(String name_of_the_class, Date d) throws IOException
returns Vector of objects with the given class name and updated on the server after that date

public Date getDate() throws IOException
returns  server's date

public String getVersion()
returns  version of this package
 

for example:

import java.io.*;
import Publish;

// this is a library :-)
class A implements Serializable
{ public A() {}
  int i; }

// test
public class Test
{
public static void main(String argv[])
{ A a = new A(),
     b=null;

// new publishing directory (Remark:  . is a root directory for your servletrunner)
Publish p=new Publish("http://your_host/servlet/PublishServlet/",".");

a.i=1;
try {
// save
p.putObject(a,"myname");
}
catch (IOException e)
   { System.out.println("can not save object !"); }

try {
// restore
b=(A) p.getObject("myname");
}
catch (IOException e)
    { System.out.println("can not restore object !"); }

// check what we get
System.out.println(b.i);

try {
// no such object
b=(A) p.getObject("C");
if (b==null) System.out.println("Can not find object C !");
}
catch (IOException e)
    { System.out.println("can not restore object C !"); }
}
}

Some  tips:

// save object and get its name
String s;
s=p.putObject(new A());

// get all objects of class A
Vector v;
v=getObjects("A");
System.out.println("How many objects: "+v.size());
A a=(A)v.elementAt(0);

// get all objects of class A saved during the last 3 min
Date d=new Date();
long t=d.getTime();
v=getObjects("A",new Date(t-1000*60*3));

Remark: For more complex case you can use getDate() call for client/server time zone adjustment.

Administrative console

You can use PublishServlet for monitoring existing objects. For doing that just run servlet with administrative password:
http://your_host/servlet/PublishServlet?your_password

You can set this password as an initial parameter for Publish servlet. The name of that parameter should be admin. E.g. by creating some like that in your servlet.properties file (check manual for your servletrunner):
# Publish servlet
servlet.PublishServlet.code=PublishServlet
servlet.PublishServlet.initArgs=admin=my_secret_word

By default this password is: welcome  
 

What is new in 1.13:
    - performance issue
    - console implemented
    - new interface calls

What is new in 1.12:
    - new interface calls

For downloading:

client: Publish.jar
server: PublishServlet.class
for testing: Test.java
 

 ©  ColdCafe 1999