00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package gov.lanl.isr.sensix.discovery;
00036
00037 import gov.lanl.isr.sensix.*;
00038
00039
00040 public class DescendantsImpl extends _DescendantsStub
00041 {
00042 private DiscoveryService serv;
00043
00044 public DescendantsImpl(DiscoveryService ds) {
00045 serv = ds;
00046 }
00047
00048
00049 public int[] nodes() {
00050 int len = serv.descendants_size;
00051 int[] ret = new int[len];
00052 System.arraycopy(serv.descendants_seen, 0, ret, 0, len);
00053 return ret;
00054 }
00055
00056
00057 public byte[] capabilities() {
00058 byte[] caps = new byte[serv.desc_db_size];
00059 for (int i = 0; i < serv.desc_db_size; i++)
00060 caps[i] = serv.desc_database[i].type;
00061 return caps;
00062 }
00063
00064
00065 public boolean findNode(int id) {
00066 for (int i = 0; i < serv.descendants_size; i++) {
00067 if (serv.descendants_seen[i] == id)
00068 return true;
00069 }
00070 return false;
00071 }
00072
00073
00074 public Request[] queryNetwork(byte capability)
00075 throws DiscoveryException {
00076 int num = 0;
00077 for (int i = 0; i < serv.desc_db_size; i++) {
00078 if (serv.desc_database[i].type == capability &&
00079 serv.desc_database[i].valid)
00080 num++;
00081 }
00082 if (num == 0)
00083 throw new DiscoveryException(DiscoveryError.NoCapability,
00084 "Descendant capability " +
00085 SenseUtil.capabilityToString(capability) +
00086 " unavailable");
00087
00088 Request[] objs = new Request[num];
00089 num = 0;
00090 for (int i = 0; i < serv.desc_db_size; i++) {
00091 if (serv.desc_database[i].type == capability &&
00092 serv.desc_database[i].valid) {
00093 try {
00094 objs[num] = RequestHelper.narrow(
00095 serv.orb.string_to_object(serv.desc_database[i].ior));
00096 }
00097 catch (org.omg.CORBA.SystemException e) {
00098 serv.desc_database[i].valid = false;
00099 throw new DiscoveryException(DiscoveryError.InvalidObject,
00100 SenseUtil.capabilityToString(capability) +
00101 " capability reference (descendant) from node " +
00102 Integer.toString(serv.desc_database[i].id) +
00103 " is invalid");
00104 }
00105 num++;
00106 }
00107 }
00108 return objs;
00109 }
00110
00111
00112 public Request queryNode(int id, byte capability)
00113 throws DiscoveryException {
00114 Request obj = null;
00115 int num = 0;
00116 boolean found = false;
00117 boolean cap_found = false;
00118 boolean id_found = false;
00119
00120 for (int i = 0; i < serv.desc_db_size; i++) {
00121 if (serv.desc_database[i].type == capability)
00122 cap_found = true;
00123 if (serv.desc_database[i].id == id)
00124 id_found = true;
00125
00126 if (serv.desc_database[i].type == capability &&
00127 serv.desc_database[i].id == id && serv.sib_database[i].valid) {
00128 try {
00129 obj = RequestHelper.narrow(
00130 serv.orb.string_to_object(serv.desc_database[i].ior));
00131 }
00132 catch (org.omg.CORBA.SystemException e) {
00133 serv.desc_database[i].valid = false;
00134 throw new DiscoveryException(DiscoveryError.InvalidObject,
00135 SenseUtil.capabilityToString(capability) +
00136 " capability reference from node " +
00137 Integer.toString(id) + " is invalid");
00138 }
00139 found = true;
00140 break;
00141 }
00142 }
00143 if (cap_found == false)
00144 throw new DiscoveryException(DiscoveryError.NoCapability,
00145 "Capability " +
00146 SenseUtil.capabilityToString(capability) +
00147 " unavailable");
00148 else if (id_found == false)
00149 throw new DiscoveryException(DiscoveryError.NoNode,
00150 "Node " + Integer.toString(id) +
00151 " unavailable");
00152 else if (found == false)
00153 throw new DiscoveryException(DiscoveryError.NoCapability,
00154 "Capability " +
00155 SenseUtil.capabilityToString(capability) +
00156 " on node " + Integer.toString(id) +
00157 " unavailable");
00158 return obj;
00159 }
00160 }