Source code: cxtable/core_comm/xConnectPool.java
1 package cxtable.core_comm;
2
3 import cxtable.*;
4
5 /*this class is the storage manager for xConnect objects... one
6 of the things compared to the new xConnects created... (The other
7 is the client xRegistry...to make sure that the actual new connect isn't
8 already completely processed...)... It can either create a new
9 xConnect from the data provided...or it can handle an xConnect object.
10 */
11
12
13 import java.util.Vector;
14
15 public class xConnectPool implements xRemoveListen{
16
17 private Vector connects;
18 private boolean debug=true;
19 private xLineSplit xls=new xLineSplit();
20
21 public xConnectPool()
22 {
23 connects=new Vector();
24 }
25
26 public boolean add(String user, String name, String regid, xConnectHook xch, String my_ip, String my_port)
27 {
28 if (user.equals("")==true){
29 return false;}
30 boolean added_one=false;
31 String ip=xls.ssplit("IP",user);
32 String nm=xls.ssplit("NAME",user);
33 String lreg = xls.ssplit("REG_ID",user);
34 int pt=0;
35 try {pt=Integer.parseInt(xls.ssplit("PORT",user));}
36 catch(Exception e){
37 pt=0;}
38
39 if (ip.equals("")|nm.equals("")|lreg.equals(""))
40 {
41 System.out.println("Skipping this connect, incomplete");
42 return false;}
43 if (debug==true){System.out.println("Adding:"+nm+" to connect pool");}
44 xConnect xcn=new xConnect(ip,nm,lreg,name,regid,pt,my_ip,my_port);
45 add(xcn);
46 xch.process(xcn);
47 added_one=true;
48
49 /* if ONE got added, true..*/
50 return added_one;
51 }
52
53
54
55 private boolean add(xConnect xc)
56 {
57 /*does this work? It is checking to see if one of what it currently has
58 matches this xConnect*/
59 if (connects.size() == 0){connects.addElement(xc);
60 xc.setRemoveListen(this);
61 return true;}
62 xConnect[] xcons = on();
63 for (int i=0; i<xcons.length; i++)
64 {
65 if (xConnect.are_equal(xc,xcons[i])==true)
66 {
67 return false;}
68 }
69 connects.addElement(xc);
70 return true;
71 }
72
73 public void remove(xRemovable r)
74 {
75 try {xConnect xx = (xConnect)r;
76 boolean b= remove(xx);
77 }
78 catch(Exception e){
79 }
80 }
81
82 public boolean remove(xConnect xc, xClientConn x)
83 {
84 xConnect[] xcons=on();
85 for (int i=0; i<xcons.length; i++)
86 {
87 if (xc==xcons[i])
88 {
89 if (x.get_Name() == null)
90 {
91 String sn=xc.get_ServName()+"(as_client_pe)";
92
93 x.set_Name(sn);
94 System.out.println("Set xcc-client name to:"+sn);
95 }
96 if (x.getServerID().equals(""))
97 {
98 String sr=xc.get_ServReg();
99 x.setServerID(sr);
100 System.out.println("Set xcc-servreg to:"+sr);
101 }
102 if (x.getClientID().equals(""))
103 {
104 String rg=xc.get_RegID();
105 x.setClientID(rg);
106 System.out.println("Set xcc-clientid to:"+rg);
107 }
108 System.out.println("Removing "+xcons[i].get_ServName()+" from pool");
109 connects.removeElementAt(i);
110 return true;
111 }
112 }
113 return false;
114 }
115
116 public boolean remove(xConnect xc)
117 {
118 xConnect[] xcons = on();
119 for (int i=0; i<xcons.length; i++)
120 {
121 if (xc == xcons[i]) {
122 System.out.println("Removing "+xcons[i].get_ServName()+" from pool");
123 connects.removeElementAt(i);
124 return true;}
125 }
126 return false;
127 }
128 public xConnect[] on_(){return on();}
129
130 private synchronized xConnect[] on()
131 {
132 xConnect[] xcs = new xConnect[connects.size()];
133 if (xcs.length == 0){
134 return xcs;}
135 if (debug==true)
136 {System.out.println("xConnectPool..dump from .on()");}
137 for (int i=0; i<xcs.length;i++)
138 {
139 xcs[i] = (xConnect)connects.elementAt(i);
140 if (debug==true) {System.out.println("Remote:"+xcs[i].get_ServName());}
141 }
142
143
144 return xcs;
145 }
146
147 /*done?*/
148 }