package com.nailabs.abac.test; import com.nailabs.abac.process.*; import com.nailabs.abac.credential.*; import edu.stanford.peer.rbtm.credential.*; import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ClientRTMLService extends UnicastRemoteObject implements NegotiatorFactory { static HashMap configs = new HashMap(); public static final int PORT = 6666; FrontierManager frontiers; boolean isDone = false; static { try { LocateRegistry.createRegistry(1099); System.out.println("Creating default registry on port 1099..."); } catch(Exception ex) { ex.printStackTrace(); } } public ClientRTMLService(int port) throws RemoteException { super(); } public ClientRTMLService() throws RemoteException { this(PORT); } public Remote getNegotiator(String entity, Negotiator peer) throws RemoteException { System.out.println("Looking up negotiator for " + entity); if(!FrontierManager.getFrontiers().contains(entity))return null; Entity oppo = peer.getSelf(); HashMap config = (HashMap)configs.get(entity); Entity self = (Entity)config.get("EntityID"); config.put("Peer", oppo); NegotiationContext context = new NegotiationContext(config); TextGraphObserver observer = new TextGraphObserver(entity); RMINegotiator agent = null; Remote stub = null; // grab a set of credential graph engines System.out.println("Received request for " + entity + " from " + oppo.toString()); try { agent = new RMINegotiator(context); context.getGraph().addObserver(observer); //stub = (Negotiator)exportObject(agent); stub = (agent == null)? null: toStub(agent); } catch(Exception ex) { ex.printStackTrace(); } System.out.println("agent = " + agent); System.out.println("stub = " + stub); // construct a new negotiation context return stub; } public void kill() throws RemoteException { isDone = true; } public static void main(String arg[]) { //if (System.getSecurityManager() == null) { // System.setSecurityManager(new RMISecurityManager()); //} Vector entities = new Vector(arg.length); for(int i = 0; i < arg.length; i++) { System.out.print("Loading from "); System.out.println(arg[i]); //check for int port number (TBD) HashMap config = RtmlTest.loadConfiguration(arg[i]); RtmlEntity id = (RtmlEntity)config.get("EntityID"); //System.out.print(" (config = "); //System.out.print(config); //System.out.println("), "); FrontierManager.addFrontier(config); configs.put(id.getHash(), config); configs.put(id.getName(), config); entities.add(id.getName()); System.out.println("\nLoaded configuration for " + id); } System.out.println("."); try { ClientRTMLService service = new ClientRTMLService(); Naming.rebind("ClientRTMLService", service); UIManager.setLookAndFeel (UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception ex) { ex.printStackTrace(); } //...create the components to go into the frame... final JFrame frame = new JFrame("TTG Callback Admin"); JButton discoverButton = new JButton("Rediscover"); JButton exitButton = new JButton("Exit"); JPanel buttonBar = new JPanel(); final JList list = new JList(entities); JLabel title = new JLabel("Negotiators Running:"); JPanel contents = new JPanel(); JScrollPane listScroller = new JScrollPane(list); Dimension dim = new Dimension(300, 80); title.setAlignmentX(Component.CENTER_ALIGNMENT); list.setSelectedIndex(0); listScroller.setPreferredSize(new Dimension(250, 80)); listScroller.setMinimumSize(new Dimension(250, 80)); listScroller.setAlignmentX(Component.CENTER_ALIGNMENT); exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); discoverButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name = (String)list.getSelectedValue(); System.out.println("Rediscovering for " + name); HashMap config = (HashMap)configs.get(name); RtmlEntity id = (RtmlEntity)config.get("EntityID"); RtmlFrontier frontier = (RtmlFrontier)RtmlFrontier.getFrontier(id); frontier.init(config); } }); contents.setLayout(new BoxLayout(contents, BoxLayout.Y_AXIS)); buttonBar.add(discoverButton); buttonBar.add(exitButton); buttonBar.setAlignmentX(Component.CENTER_ALIGNMENT); //...stick them in a container named contents... frame.getContentPane().add(contents); contents.add(Box.createRigidArea(new Dimension(0,5))); contents.add(title); contents.add(Box.createRigidArea(new Dimension(0,5))); contents.add(listScroller); contents.add(buttonBar); //contents.setPreferredSize(dim); //contents.setMinimumSize(dim); //Finish setting up the frame, and show it. //frame.addWindowListener(...); frame.pack(); frame.setLocation(new Point(100,100)); frame.setVisible(true); } }