This project has retired. For details please refer to its Attic page.
UddiReplication xref
View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.v3.client.cli;
17  
18  import java.math.BigInteger;
19  import java.util.List;
20  import java.util.logging.Level;
21  import java.util.logging.Logger;
22  import javax.xml.bind.JAXB;
23  import javax.xml.ws.BindingProvider;
24  import org.apache.commons.configuration.ConfigurationException;
25  import org.apache.juddi.v3.client.UDDIService;
26  import org.apache.juddi.v3.client.config.UDDIClient;
27  import org.uddi.repl_v3.ChangeRecord;
28  import org.uddi.repl_v3.ChangeRecordIDType;
29  import org.uddi.repl_v3.ChangeRecords;
30  import org.uddi.repl_v3.DoPing;
31  import org.uddi.repl_v3.GetChangeRecords;
32  import org.uddi.repl_v3.HighWaterMarkVectorType;
33  import org.uddi.v3_service.UDDIReplicationPortType;
34  
35  /**
36   *
37   * @author Alex O'Ree
38   */
39  class UddiReplication {
40  
41          private UDDIReplicationPortType uddiReplicationPort = null;
42  
43          public UddiReplication(UDDIClient client, String nodename) throws ConfigurationException {
44  
45                  uddiReplicationPort = new UDDIService().getUDDIReplicationPort();
46                  ((BindingProvider) uddiReplicationPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, client.getClientConfig().getUDDINode(nodename).getReplicationUrl());
47          }
48  
49          protected String doPing() {
50                  try {
51                          String doPing = uddiReplicationPort.doPing(new DoPing());
52                          System.out.println("Ping Success, remote node's id is " + doPing);
53                          return doPing;
54                  } catch (Exception ex) {
55                          Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex);
56                  }
57                  return null;
58          }
59  
60          protected void getHighWatermarks() {
61                  try {
62                          List<ChangeRecordIDType> highWaterMarks = uddiReplicationPort.getHighWaterMarks();
63                          System.out.println("Success....");
64                          System.out.println("Node, USN");
65                          for (int i = 0; i < highWaterMarks.size(); i++) {
66                                  System.out.println(
67                                          highWaterMarks.get(i).getNodeID() + ", "
68                                          + highWaterMarks.get(i).getOriginatingUSN());
69                          }
70                  } catch (Exception ex) {
71                          Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex);
72                  }
73          }
74  
75          protected void getChangeRecords(Long record, String sourcenode) {
76                  try {
77                          HighWaterMarkVectorType highWaterMarkVectorType = new HighWaterMarkVectorType();
78  
79                          highWaterMarkVectorType.getHighWaterMark().add(new ChangeRecordIDType(doPing(), record));
80                          GetChangeRecords req = new GetChangeRecords();
81                          req.setRequestingNode(sourcenode);
82                          req.setChangesAlreadySeen(highWaterMarkVectorType);
83                          req.setResponseLimitCount(BigInteger.valueOf(100));
84                          ChangeRecords res = uddiReplicationPort.getChangeRecords(req);
85                          List<ChangeRecord> changeRecords = res.getChangeRecord();
86                          System.out.println("Success...." + changeRecords.size() + " records returned");
87                          System.out.println("Node, USN, type");
88                          for (int i = 0; i < changeRecords.size(); i++) {
89                                  System.out.println(
90                                          changeRecords.get(i).getChangeID().getNodeID() + ", "
91                                          + changeRecords.get(i).getChangeID().getOriginatingUSN() + ": "
92                                          + getChangeType(changeRecords.get(i)));
93                                  JAXB.marshal(changeRecords.get(i), System.out);
94                          }
95                  } catch (Exception ex) {
96                          Logger.getLogger(UddiReplication.class.getName()).log(Level.SEVERE, null, ex);
97                  }
98          }
99  
100         protected String getChangeType(ChangeRecord get) {
101                 if (get.getChangeRecordAcknowledgement() != null) {
102                         return "ACK";
103                 }
104                 if (get.getChangeRecordConditionFailed() != null) {
105                         return "ConditionFailed";
106                 }
107                 if (get.getChangeRecordCorrection() != null) {
108                         return "Correction";
109                 }
110                 if (get.getChangeRecordDelete() != null) {
111                         return "Deletion";
112                 }
113                 if (get.getChangeRecordDeleteAssertion() != null) {
114                         return "Delete Assertion";
115                 }
116                 if (get.getChangeRecordHide() != null) {
117                         return "Hide tmodel";
118                 }
119                 if (get.getChangeRecordNewData() != null) {
120                         return "New Data";
121                 }
122                 if (get.getChangeRecordNewDataConditional() != null) {
123                         return "New data conditional";
124                 }
125                 if (get.getChangeRecordNull() != null) {
126                         return "Null";
127                 }
128                 if (get.getChangeRecordPublisherAssertion() != null) {
129                         return "New publisher assertion";
130                 }
131                 return null;
132         }
133 
134 }