Skip to Content.
Sympa Menu

perfsonar-dev - [pS-dev] [GEANT/SA2/ps-java-services] r5764 - trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType

Subject: perfsonar development work

List archive

[pS-dev] [GEANT/SA2/ps-java-services] r5764 - trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType


Chronological Thread 
  • From:
  • To:
  • Subject: [pS-dev] [GEANT/SA2/ps-java-services] r5764 - trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType
  • Date: Wed, 13 Oct 2010 15:26:25 +0100

Author: psnc.pikusa
Date: 2010-10-13 15:26:25 +0100 (Wed, 13 Oct 2010)
New Revision: 5764

Added:

trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
Log:
New Message Handler for Metadata Key Request to fix bug 508

Added:
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
===================================================================
---
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
(rev 0)
+++
trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/service/measurementArchive/rrdType/MetadataKeyMessageHandler.java
2010-10-13 14:26:25 UTC (rev 5764)
@@ -0,0 +1,183 @@
+package main.java.org.perfsonar.service.measurementArchive.rrdType;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.perfsonar.base2.service.exceptions.PerfSONARException;
+import org.perfsonar.base2.service.messages.GenericMessageHandler;
+import org.perfsonar.base2.service.requesthandler.ServiceMessage;
+import org.perfsonar.base2.xml.nmwg.Data;
+import org.perfsonar.base2.xml.nmwg.Message;
+import org.perfsonar.base2.xml.nmwg.Metadata;
+
+public class MetadataKeyMessageHandler extends GenericMessageHandler {
+
+
+ private static final Logger logger =
Logger.getLogger(GenericMessageHandler.class.getName());
+
+
+ public MetadataKeyMessageHandler() throws PerfSONARException {
+ super();
+ }
+
+
+ protected MessagePair mergeMultipleResponses(ArrayList<MessagePair>
messagePairs) {
+
+ final Map<String, String> ids = new Hashtable<String,
String>();
+
+ if (messagePairs == null || messagePairs.size() == 0)
+ return null;
+ else if (messagePairs.size() == 1)
+ return messagePairs.get(0);
+ else {
+
+ int metaid=0;
+ int dataid=0;
+
+ //create new common response message
+ Message respMessage = new Message();
+
+
+
+ logger.info("MOJA METODA");
+ /*
+ * Bug 508 fixing - BEGIN
+ */
+
+ //Prepare Message Text
+ StringBuffer responseText = new StringBuffer();
+ String t =
messagePairs.get(0).getRequest().getElement().getAttribute("type");
+ String type = (t == null? "": t.replaceFirst("Request",
"Response"));
+ responseText.append("<nmwg:message type=\"" + type + "\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";
xmlns=\"http://ggf.org/ns/nmwg/base/2.0/\";>");
+
+ //Concatenate Messages
+ int messageCounter = 0;
+ for (MessagePair messagePair : messagePairs) {
+
+ if(messagePair.getResponse().getText() != null &&
messagePair.getResponse().getElement() == null){
+ //If it's true it means that on message pairs
list there is no response which has element object so responses can be
concatenated
+
+
responseText.append(messagePair.getResponse().getText());
+ messageCounter++;
+
+ }
+ else{
+ break;
+ }
+ }
+
+ responseText.append("</nmwg:message>");
+
+
+ //If it's true it means that on message pairs list there is
no response which has element object so responses can be concatenated
+ if(messagePairs.size() == messageCounter){
+
messagePairs.get(0).getResponse().setText(responseText.toString());
+ return messagePairs.get(0);
+
+ }
+
+ /*
+ * Bug 508 fixing - END
+ */
+
+
+ for (MessagePair messagePair : messagePairs) {
+
+ //ServiceMessage request = messagePair.getRequest();
+ ServiceMessage response = messagePair.getResponse();
+ Message m = (Message) response.getElement();
+
+
+
+ if (m == null) return messagePair;
+
+ Collection<Metadata> metadatas =
m.getMetadataMap().values();
+ Collection<Data> datas = m.getDataMap().values();
+
+ //for each metadata
+ for (Metadata meta1 : metadatas) {
+
+ //get old meta id
+ String meta1id = meta1.getId();
+ //compute new meta id
+ String newMeta1id = meta1id+"_"+metaid;
+
+ //set new id
+ meta1.setId(newMeta1id);
+
+ metaid++;
+
+ ids.put(meta1id, newMeta1id);
+
+ /*
+ * TODO:
+ * subject chaining reference
+ * if there is metadata/subject with
+ * metadataRefId, it should be changed
+ *
+ * perhaps some metadata-id mapping table
+ * should be prepared and then all metadata
+ * should be iterated and subjects changed?
+ *
+ * something like:
+ *
+ * mapping.add(oldId, newId);
+ *
+ */
+ if ((meta1.getSubject() != null)
+ &&
(meta1.getSubject().getMetadataIdRef() != null)) {
+ if
(ids.get(meta1.getSubject().getMetadataIdRef()) != null)
+
meta1.getSubject().setMetadataIdRef(ids.get(meta1.getSubject().getMetadataIdRef()));
+ }
+
+ //put metadata to new common response message
+ respMessage.setMetadata(meta1);
+
+ //find all data linked to meta
+ for (Data data1 : datas) {
+
+ //if data's metadata id res == metadata id
+ //put data
+ if (data1.getMetadataIdRef().equals(meta1id))
{
+
+ data1.setId(data1.getId() + "_"+dataid);
+ //change data metadata id ref to new meta
id
+ data1.setMetadataIdRef(newMeta1id);
+
+ //put changed data to response common
message
+ respMessage.setData(data1);
+
+ dataid++;
+
+ } //if
+ } //datas
+ } //metadata
+
+ }
+
+ return new MessagePair(null, new
ServiceMessage(respMessage));
+
+ }
+ }
+
+
+ class MessagePair {
+ private ServiceMessage request = null;
+ private ServiceMessage response = null;
+
+ public MessagePair(ServiceMessage request, ServiceMessage
response) {
+ this.request = request;
+ this.response = response;
+ }
+
+ public void setRequest(ServiceMessage request) { this.request =
request; }
+ public void setResponse(ServiceMessage response) { this.response
= response; }
+ public ServiceMessage getRequest() { return request; }
+ public ServiceMessage getResponse() { return response; }
+ }
+
+}



  • [pS-dev] [GEANT/SA2/ps-java-services] r5764 - trunk/perfsonar-java-rrd-ma/src/main/java/org/perfsonar/se rvice/measurementArchive/rrdType, svn-noreply, 10/13/2010

Archive powered by MHonArc 2.6.16.

Top of Page