All Packages Class Hierarchy This Package Previous Next Index
Voyager1 - Remote creation and manipulation of containers.
Voyager2 - Iteration through a remote container.
Voyager3 - Distributed algorithms on a remote container.
Voyager4A - Persist a container.
Voyager4B - Retrieve a persisted container.
Voyager1 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.voyager.*;
import com.objectspace.voyager.*;
/**
* Remote creation and manipulation of containers.
*
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Voyager1
{
/**
* This example only works with ObjectSpace Voyager(tm).
* Visit the Voyager homepage for more information.
*/
public static void main( String[] args )
{
try
{
// create a remote map that allows duplicate keys
VHashMap map = new VHashMap( true, "localhost:8000" );
// fill remote map
map.add( "city", "Austin" );
map.add( "song", "Texas Fight!" );
map.add( "mascot", "Bevo" );
map.add( "mascot", "Longhorns" );
System.out.println( "map = " + map ); // prints locally
// query remote container
System.out.println( "map.size() = " + map.size() );
System.out.println( "map.empty() = " + map.isEmpty() );
System.out.println( "map.get( \"song\" ) = " + map.get( "song" ) );
// mutate remote container
map.clear();
System.out.println( "\nafter remote map is cleared..." );
System.out.println( "map.size() = " + map.size() );
System.out.println( "map.empty() = " + map.isEmpty() );
System.out.println( "map.get( \"song\" ) = " + map.get( "song" ) );
}
catch ( VoyagerException ex )
{
System.err.println( "caught: " + ex );
}
Voyager.shutdown();
}
}
voyager(tm) 2.0 beta 1, copyright objectspace 1997
address = 285.42.132.60:1082
map = HashMap( Pair( mascot, Bevo ), Pair( mascot, Longhorns ), Pair( song, Texas Fight! ), Pair( city, Austin ) )
map.size() = 4
map.empty() = false
map.get( "song" ) = Texas Fight!
after remote map is cleared...
map.size() = 0
map.empty() = true
map.get( "song" ) = null
Voyager2 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.voyager.*;
import com.objectspace.voyager.*;
/**
* Iteration through a remote container.
*
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Voyager2
{
/**
* This example only works with ObjectSpace Voyager(tm).
* Visit the Voyager homepage for more information.
*/
public static void main( String[] args )
{
try
{
// create a remote list
VSList list = new VSList( "localhost:8000" );
new VSListIterator(); // force class loading
// fill remote list
list.add( "yakko" );
list.add( "wakko" );
list.add( "dot" );
System.out.println( "lowercase = " + list );
// obtain a local iterator to the remote list
list.setVirtual( true );
ForwardIterator iterator = list.start();
list.setVirtual( false );
// change all elements in remote list to uppercase
while ( !iterator.atEnd() )
{
String current = (String)iterator.get();
iterator.put( current.toUpperCase() );
iterator.advance();
}
System.out.println( "uppercase = " + list );
}
catch ( VoyagerException ex )
{
System.err.println( "caught: " + ex );
}
Voyager.shutdown();
}
}
voyager(tm) 2.0 beta 1, copyright objectspace 1997
address = 285.42.132.60:1084
lowercase = SList( yakko, wakko, dot )
uppercase = SList( YAKKO, WAKKO, DOT )
Voyager3 Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.functions.*;
import com.objectspace.jgl.predicates.*;
import com.objectspace.jgl.voyager.*;
import com.objectspace.jgl.voyager.algorithms.*;
import com.objectspace.voyager.*;
/**
* Distributed algorithms on a remote container.
*
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Voyager3
{
/**
* This example only works with ObjectSpace Voyager(tm).
* Visit the Voyager homepage for more information.
*/
public static void main( String[] args )
{
try
{
// create and fill remote container
VDeque deque = new VDeque( "localhost:8000" );
new VDequeIterator(); // force class loading
deque.add( "Texas Fight!" );
deque.add( "Bevo" );
deque.add( "Hook 'Em" );
System.out.println( "deque = " + deque );
// print the contents of the container at the remote location
VApplying.forEach( deque, new Print(), "localhost:8000" );
// sort the remote array
VSorting.sort( deque, "localhost:8000" );
System.out.println( "\ndefault sort = " + deque );
// sort the remote array using a custom comparator
VSorting.sort( deque, new LessString(), "localhost:8000" );
System.out.println( " alpha sort = " + deque );
// expand the remote container
deque.pushFront( "White" );
deque.pushBack( "White" );
deque.pushFront( "White" );
deque.pushBack( "White" );
// perform an algorithm on a subrange of the remote container
System.out.println( "\nbefore = " + deque );
deque.setVirtual( true );
BidirectionalIterator b = (BidirectionalIterator)deque.start();
BidirectionalIterator e = (BidirectionalIterator)deque.finish();
b.advance();
e.retreat();
deque.setVirtual( false );
VReplacing.replace( b, e, "White", "Orange", "localhost:8000" );
System.out.println( " after = " + deque );
}
catch ( VoyagerException ex )
{
System.err.println( "caught: " + ex );
}
Voyager.shutdown();
}
}
voyager(tm) 2.0 beta 1, copyright objectspace 1997
address = 285.42.132.60:1086
deque = Deque( Texas Fight!, Bevo, Hook 'Em )
default sort = Deque( Hook 'Em, Texas Fight!, Bevo )
alpha sort = Deque( Bevo, Hook 'Em, Texas Fight! )
before = Deque( White, White, Bevo, Hook 'Em, Texas Fight!, White, White )
after = Deque( White, Orange, Bevo, Hook 'Em, Texas Fight!, Orange, White )
Voyager4A Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.voyager.*;
import com.objectspace.voyager.*;
/**
* Persist a container.
*
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Voyager4A
{
/**
* This example only works with ObjectSpace Voyager(tm).
* Visit the Voyager homepage for more information.
*/
public static void main( String[] args )
{
try
{
// create and fill a remote map
VHashMap map = new VHashMap( "localhost:8000/JGL4" );
map.add( "Spider-Man", "Peter Parker" );
map.add( "Wolverine", "Logan" );
map.add( "Batman", "Bruce Wayne" );
map.add( "Oracle", "Barbara Gordon" );
map.liveForever(); // do not garbage collect
map.saveNow(); // save copy to database of server 8000
System.out.println( "saved " + map );
}
catch ( VoyagerException ex )
{
System.err.println( "caught: " + ex );
}
Voyager.shutdown();
}
}
voyager(tm) 2.0 beta 1, copyright objectspace 1997
address = 285.42.132.60:1088
saved HashMap( Pair( Wolverine, Logan ), Pair( Batman, Bruce Wayne ), Pair( Spider-Man, Peter Parker ), Pair( Oracle, Barbara Gordon ) )
Voyager4B Example Code
// Copyright(c) 1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.voyager.*;
import com.objectspace.voyager.*;
/**
* Retrieve a persisted container.
*
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Voyager4B
{
/**
* This example only works with ObjectSpace Voyager(tm).
* Visit the Voyager homepage for more information.
*/
public static void main( String[] args )
{
try
{
// connect to persistent map in server 8000
VHashMap map = (VHashMap)VObject.forObjectAt("localhost:8000/JGL4");
query( map, "Spider-Man" );
query( map, "Mr. Fantastic" );
map.dieNow(); // kill map, remove from database
}
catch ( VoyagerException ex )
{
System.err.println( "caught: " + ex );
}
Voyager.shutdown();
}
public static void query( VHashMap map, String hero ) throws VoyagerException
{
Object name = map.get( hero );
if ( name == null )
System.out.println( hero + " is not in the database" );
else
System.out.println( hero + " is really " + name );
}
}
voyager(tm) 2.0 beta 1, copyright objectspace 1997
address = 285.42.132.60:1090
Spider-Man is really Peter Parker
Mr. Fantastic is not in the database
All Packages Class Hierarchy This Package Previous Next Index