source: fedd/abac-src/ttg/process/StaticNegotiator.java @ e19b75c

axis_examplecompt_changesinfo-opsversion-2.00version-3.01version-3.02
Last change on this file since e19b75c was eea2aa4, checked in by Jay Jacobs <Jay.Jacobs@…>, 15 years ago

Added static negotiator to be non-rmi based negotiator.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1package com.nailabs.abac.process;
2
3import com.nailabs.abac.trust.*;
4import com.nailabs.abac.test.*;
5import edu.stanford.peer.rbtm.credential.Entity;
6
7/**
8 * This class is a concrete negotiator implementation isolated from the
9 * underlying communications transport mechanism.
10 */
11public class StaticNegotiator {
12    /**
13     * The peer with which this instance negotiates.
14     */
15    protected StaticNegotiator peer;
16
17    /**
18     * The context for the current negotiation, including a trust target graph,
19     * strategy, and frontier manager instances.
20     */
21    protected NegotiationContext context;
22
23    /**
24     * Default constructor for the client-side negotiatior. This negotiator
25     * is requesting access to a resource.
26     */
27    public StaticNegotiator(NegotiationContext nc) { 
28        context = nc;
29    }
30
31    /**
32     * Constructor for the server-side negotiator. This negotiator has a
33     * resource that needs protection.
34     */
35    public StaticNegotiator(TargetNode root, StaticNegotiator peer) {
36        setPeer(peer); 
37    } 
38   
39    public Entity getSelf() 
40    {
41        return context.getSelf();
42    }
43
44    /**
45     * initial a new root node and start the negotiation process.
46     */
47    public boolean negotiate() {
48        TTG graph = context.getGraph();
49        Strategy s = context.getStrategy();
50        SatisfactionState state;
51        int i = 0;
52        debug("pre-processing locally...");
53        //perform strategy once
54        s.iterate();
55        Message changes = graph.getChanges();
56        graph.reset();
57        do {
58            debug("processing cycle = " + ++i);
59            debug("sending message " + changes);
60            System.out.println("Sending message: ");
61            System.out.println(changes.toXML());
62        try {
63            Message updates = peer.receive(changes);
64            debug("receiving message " + updates);
65            changes = receive(updates);
66        }
67        catch(Exception ex) {
68            Debug.rbtmStop();
69            ex.printStackTrace();
70            return false;
71        }
72            state = new SatisfactionState(context.getStrategy().getSatisfactionState());
73            debug("StaticNegotiator:  primary trust target  is " + state);
74        }while(state.getState() == SatisfactionState.UNKNOWN && i <= 100);
75        // out of the loop so we need to return success or failure
76        return (state.getState() == SatisfactionState.SATISFIED);
77    }
78
79
80    /** set the other negotiator dynamically */
81    public void setPeer(StaticNegotiator peer) {
82        this.peer = peer;
83    }
84
85    public void setRoot(TrustTarget tt) {
86        context.getGraph().setRoot(tt);
87        //TargetNode node = (TargetNode)context.getGraph().getNodeByHash(tt);
88        //context.getStrategy().addToWorklist(node);
89    }
90   
91
92    /**
93     * Synchronously receive a message which can contain multiple operations
94     * from an peer and then return the updates to the originating
95     * peer.
96     */
97    public Message receive(Message msg) throws Exception {
98        Strategy strategy = context.getStrategy();
99        TTG graph = context.getGraph();
100        Message results = null;
101
102        //for(int i = 0, max = msg.getOperationsCount(); i < max; i++) {
103        //    System.out.println("max = " + max);
104        //   try {
105        //      Operation op = msg.getNextOperation();
106        //      op.perform(graph);
107        //    }
108        //    catch(Exception ex) {
109        //      ex.printStackTrace();
110        //    }
111        //}
112        debug("begin receive");
113        graph.update(msg);
114        debug("graph has been updated");
115        strategy.process(msg);
116        debug("strategy has processed the work list");
117        results = graph.getChanges();
118        debug("grabbing the delta list = " + results);
119        graph.reset();
120
121        debug("end receive");   
122        return results;
123    }
124   
125    /** convenience method for printing messages */
126    public void debug(String message) {
127        StringBuffer buff = new StringBuffer("StaticNegotiator[");
128        buff.append(context.getSelf()).append("]: ").append(message);
129        //System.out.println(buff);
130        Debug.debug("negotiate", buff.toString());
131    }
132}
Note: See TracBrowser for help on using the repository browser.