1 6 7 package SOFA.SOFAnet.Search.RMI; 8 9 import SOFA.SOFAnet.Search.*; 10 import SOFA.SOFAnet.Repository.NodeInfo; 11 import java.util.*; 12 13 18 public class RMISearchClient implements SearchInterface 19 { 20 private RMISearchCenter center; 21 22 23 public RMISearchClient(RMISearchCenter center) 24 { 25 this.center = center; 26 } 27 28 33 public void reply(SearchReply reply) throws SearchException 34 { 35 String requestingNodeName = reply.getRequestID().getSourceNode(); 36 37 NodeInfo requestingNodeInfo = new NodeInfo(); 38 try 39 { 40 requestingNodeInfo.setNodeName(requestingNodeName); 41 } 42 catch (NodeInfo.InvalidNodeNameException e) 43 { 44 throw new SearchException("Invalid name of SOFA node: " + requestingNodeName, e); 45 } 46 47 List rmiSearchConnections = center.getRMISearchConnections(); 49 synchronized (rmiSearchConnections) 50 { 51 Iterator it = rmiSearchConnections.iterator(); 52 while (it.hasNext()) 53 { 54 RMISearchConnection connection = (RMISearchConnection)it.next(); 55 if (connection.isNode(requestingNodeName)) 56 { 57 try 58 { 59 connection.sendReply(reply); 60 } 61 catch (RMISearchException e) 62 { 63 throw new SearchException(e.getMessage(), e); 64 } 65 66 return; 67 } 68 } 69 } 70 71 RMISearchConnection connection = new RMISearchConnection(requestingNodeInfo, null, true); 73 74 try 75 { 76 connection.sendReply(reply); 77 } 78 catch (RMISearchException e) 79 { 80 throw new SearchException(e.getMessage(), e); 81 } 82 83 } 84 85 91 public void request(SearchRequest request) throws SearchException 92 { 93 RMISearchCollector collector = center.newCollector(); 94 95 collector.setup(request.getSearchPattern(), request.getFirstOnly(), request.getShareGroup(), request.getTimeout()); 96 List replies = collector.request(); 97 center.removeCollector(collector.getRequestMark()); 98 99 request.setReplies(replies); 100 request.setErrCode(0); 101 } 102 103 } 104 | Popular Tags |