Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: alice/tuprolog/lib/LuceLibrary.java


1   /*
2    *   LuceLibrary.java
3    *
4    * Copyright 2000-2001 deis.unibo.it
5    *
6    * This software is the proprietary information of deis.unibo.it
7    * Use is subject to license terms.
8    *
9    */
10  package alice.tuprolog.lib;
11  import  alice.tuprolog.*;
12  import java.io.*;
13  import  java.util.*;
14  
15  import alice.logictuple.*;
16  import alice.infrastructure.Luce;
17  import alice.luce.*;
18  
19  /**
20   *
21   * this library allows the exploitation
22   * of the LuCe coordination alice.infrastructure.
23   * <p>
24   * only LuCe nodes installed on default port
25   * (that is 'LuCe infrastructure')
26   * are reachable through this library.
27   * <p>
28   * refer to tuplemedium documentation
29   * for understanding of coordination primitives
30   *
31   */
32  public class LuceLibrary extends Library {
33  
34      public LuceLibrary(){
35          theory=
36              ":- op(  600, xfx,  '?'). \n"+
37              "TC ? out(T) :- out(T,TC). \n"+
38              "TC ? out_async(T) :- out_async(T,TC). \n"+
39              "TC ? in(T)  :- in(T,TC). \n"+
40              "TC ? inp(T) :- inp(T,TC). \n"+
41              "TC ? rd(T)  :- rd(T,TC). \n"+
42              "TC ? rdp(T) :- rdp(T,TC). \n"+
43              "TC ? set_spec(T)  :- set_spec(T,TC). \n"+
44              "TC ? get_spec(T) :- get_spec(T,TC). \n"+
45              "out(T):-out(T,default). \n"+
46              "out_async(T):-out(T,default). \n"+
47              "in(T):-in(T,default). \n"+
48              "rd(T):-rd(T,default). \n"+
49              "inp(T):-inp(T,default). \n"+
50              "rdp(T):-rdp(T,default). \n"+
51              "set_spec(T):-set_spec(T,default). \n"+
52              "get_spec(T):-get_spec(T,default). \n";
53      }
54  
55      public boolean out_2(Struct g){
56          Term arg0 = g.getTerm(0);
57          Term arg1 = g.getTerm(1);
58          TupleCentreId tid=new TupleCentreId(arg1.toString());
59          try {
60              Luce.out(tid, new LogicTuple(arg0));
61              return true;
62          } catch(Exception x) {
63              x.printStackTrace();
64              return false;
65          }
66      }
67  
68      public boolean out_async_2(Struct g){
69          Term arg0 = g.getTerm(0);
70          Term arg1 = g.getTerm(1);
71          TupleCentreId tid=new TupleCentreId(arg1.toString());
72          try {
73              Luce.outAsync(tid, new LogicTuple(arg0));
74              return true;
75          } catch(Exception x) {
76              //x.printStackTrace();
77              return false;
78          }
79      }
80  
81      public boolean in_2(Struct g){
82          Term arg0 = g.getTerm(0);
83          Term arg1 = g.getTerm(1);
84          TupleCentreId tid=new TupleCentreId(arg1.toString());
85          try {
86              LogicTuple tuple=Luce.in(tid,new LogicTuple(arg0));
87              return unify(arg0,tuple.toTerm());
88          } catch(Exception x) {
89              //x.printStackTrace();
90              return false;
91          }
92      }
93  
94      public boolean inp_2(Struct g){
95          Term arg0 = g.getTerm(0);
96          Term arg1 = g.getTerm(1);
97          TupleCentreId tid=new TupleCentreId(arg1.toString());
98          try {
99              LogicTuple tuple=Luce.inp(tid, new LogicTuple(arg0));
100             return (tuple!=null && unify(arg0,tuple.toTerm()));
101         } catch(Exception x) {
102             //x.printStackTrace();
103             return false;
104         }
105     }
106 
107     public boolean rd_2(Struct g){
108         Term arg0 = g.getTerm(0);
109         Term arg1 = g.getTerm(1);
110         TupleCentreId tid=new TupleCentreId(arg1.toString());
111         try {
112             LogicTuple tuple=Luce.rd(tid, new LogicTuple(arg0));
113             return unify(arg0,tuple.toTerm());
114         } catch(Exception x) {
115             //x.printStackTrace();
116             return false;
117         }
118     }
119 
120     public boolean rdp_2(Struct g){
121         Term arg0 = g.getTerm(0);
122         Term arg1 = g.getTerm(1);
123         TupleCentreId tid=new TupleCentreId(arg1.toString());
124         try {
125             LogicTuple tuple=Luce.rdp(tid, new LogicTuple(arg0));
126             return (tuple!=null && unify(arg0,tuple.toTerm()));
127         } catch(Exception x) {
128             //x.printStackTrace();
129             return false;
130         }
131     }
132 
133     public boolean set_spec_2(Struct g){
134         Term arg0 = g.getTerm(0);
135         Term arg1 = g.getTerm(1);
136         TupleCentreId tid=new TupleCentreId(arg1.toString());
137         try {
138             LogicTuple tuple=null;
139             if (arg0.isStruct()){
140                 tuple=Luce.setSpec(tid, new LogicTuple(arg0));
141             }
142             return (tuple!=null);
143         } catch(Exception x) {
144             x.printStackTrace();
145             return false;
146         }
147     }
148 
149     public boolean get_spec_2(Struct g){
150         Term arg0 = g.getTerm(0);
151         Term arg1 = g.getTerm(1);
152         TupleCentreId tid=new TupleCentreId(arg1.toString());
153         try {
154             LogicTuple tuple=Luce.getSpec(tid);
155             return (tuple!=null && unify(arg0,tuple.toTerm()));
156         } catch(Exception x) {
157             //x.printStackTrace();
158             return false;
159         }
160     }
161 }