From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Gerald Examples/src/examples/jndi/Client.java | 22 ++++++++ .../src/examples/jndi/InitContext.java | 11 ++++ .../src/examples/jndi/PrimaryKeyGenerator.java | 13 +++++ .../src/examples/jndi/PrimaryKeyGeneratorImpl.java | 29 ++++++++++ .../Gerald Examples/src/examples/jndi/Startup.java | 32 +++++++++++ .../Gerald Examples/src/examples/jndi/build.xml | 62 ++++++++++++++++++++++ .../src/examples/jndi/jndi.properties | 4 ++ 7 files changed, 173 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java new file mode 100644 index 0000000..1500a48 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java @@ -0,0 +1,22 @@ +package examples.jndi; + +import javax.naming.*; +import javax.rmi.*; + +public class Client { + + public static void main (String[] args) throws Exception { + + // Lookup the remote object via JNDI + Context ctx = new InitialContext(System.getProperties()); + Object remoteObject = ctx.lookup("PKGenerator"); + + // Cast the remote object, RMI-IIOP style + PrimaryKeyGenerator generator = (PrimaryKeyGenerator) + PortableRemoteObject.narrow( + remoteObject, PrimaryKeyGenerator.class); + + // Generate a PK by calling the RMI-IIOP stub + System.out.println(generator.generate()); + } +} \ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java new file mode 100644 index 0000000..dca940f --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java @@ -0,0 +1,11 @@ +package examples.jndi; + +public class InitContext { + public static void main(String args[]) throws Exception { + // Form an Initial Context + javax.naming.Context ctx = + new javax.naming.InitialContext(System.getProperties()); + System.err.println("Success!"); + } + +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java new file mode 100644 index 0000000..d866f9d --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java @@ -0,0 +1,13 @@ +package examples.jndi; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * The remote interface for the remote object. Clients use it + * for all operations on the remote object. + */ + +public interface PrimaryKeyGenerator extends Remote { + public long generate() throws RemoteException; +} \ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java new file mode 100644 index 0000000..eeb08cb --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java @@ -0,0 +1,29 @@ +package examples.jndi; + +import java.rmi.RemoteException; +import javax.rmi.PortableRemoteObject; + +/** + * The implementation of a remote object which generates primary keys + */ +public class PrimaryKeyGeneratorImpl + extends PortableRemoteObject + implements PrimaryKeyGenerator { + + private static long i = System.currentTimeMillis(); + + public PrimaryKeyGeneratorImpl() throws Exception, RemoteException { + /* + * Since we extend PortableRemoteObject, the super + * class will export our remote object here. + */ + super(); + } + + /** + * Generates a unique primary key + */ + public synchronized long generate() throws RemoteException { + return i++; + } +} \ No newline at end of file diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java new file mode 100644 index 0000000..c6e9afa --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java @@ -0,0 +1,32 @@ +package examples.jndi; +import javax.naming.*; + +/** + * A helper class which starts our RMI-IIOP server + */ +public class Startup { + + /** + * Our main() method starts things up + */ + public static void main(String args[]) throws Exception { + + /* + * Start up our PKGenerator remote object. It will + * automatically export itself. + */ + PrimaryKeyGenerator generator = new PrimaryKeyGeneratorImpl(); + + /* + * Bind our PKGenerator remote object to the JNDI tree + */ + Context ctx = new InitialContext(System.getProperties()); + ctx.rebind("PKGenerator", generator); + System.out.println("PKGenerator bound to JNDI tree."); + + // wait for clients + synchronized (generator) { + generator.wait(); + } + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml new file mode 100644 index 0000000..d7c9690 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml @@ -0,0 +1,62 @@ + + ]> + + + + &include; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties new file mode 100644 index 0000000..98cfb22 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties @@ -0,0 +1,4 @@ +java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory +#java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory +#java.naming.provider.url=file:c +java.naming.provider.url=corbaloc::localhost:3528/NameService \ No newline at end of file -- cgit v1.2.3