Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r2744 - branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages

Subject: perfsonar development work

List archive

perfsonar: r2744 - branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r2744 - branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages
  • Date: Wed, 29 Aug 2007 09:38:57 -0400

Author: mac
Date: 2007-08-29 09:38:57 -0400 (Wed, 29 Aug 2007)
New Revision: 2744

Modified:

branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages/LSRegisterRequest.java
Log:
Now supports advanced base chaining and multiple requests


Modified:
branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages/LSRegisterRequest.java
===================================================================
---
branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages/LSRegisterRequest.java
2007-08-29 09:38:22 UTC (rev 2743)
+++
branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages/LSRegisterRequest.java
2007-08-29 13:38:57 UTC (rev 2744)
@@ -4,20 +4,19 @@
*/
package org.perfsonar.service.base.messages;

-import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
-import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.ConfigurationComponent;
-import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.ggf.ns.nmwg.base.v2_0.Data;
+import org.ggf.ns.nmwg.base.v2_0.Message;
+import org.ggf.ns.nmwg.base.v2_0.Metadata;
+import org.omg.CORBA.SystemException;
+import org.perfsonar.base.exceptions.PerfSONARException;
+import org.perfsonar.base.util.XMLUtils;
import org.perfsonar.service.base.engine.ActionType;
-import org.perfsonar.service.base.engine.ServiceEngine;
-import org.perfsonar.service.base.engine.ServiceEngineFactory;
-import org.perfsonar.service.base.util.ResultCodesUtil;

-import org.perfsonar.base.exceptions.PerfSONARException;

-import org.ggf.ns.nmwg.base.v2_0.Message;
-
-
/**
* @author Maciej Glowiak
* MessageHandler for LS Regiser Request
@@ -29,83 +28,99 @@
* actually data triggers, and the message shouldn't be splitted
* into separate requests!
*
- *
+
*/
-public class LSRegisterRequest implements MessageHandler {
+public class LSRegisterRequest extends LSRequest {

- protected String type = null;
- protected LoggerComponent logger = null;
- protected ConfigurationComponent configManager = null;
- protected String serviceType = null;
- protected String serviceEngineClassName = null;
- protected ServiceEngine serviceEngine = null;

-
/**
* @throws SystemException
*/
public LSRegisterRequest() throws PerfSONARException {
+
+ super();
+ System.out.println(" -------- NEW ----------");

- // get a logger
- logger = (LoggerComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.LOGGER);
-
- // Config manager used to determine MA type
- configManager = (ConfigurationComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.CONFIG);
-
logger.debug("LSRegisterRequest: MessageHandler created");
- setType(ActionType.LS_REGISTER);
-
-
- serviceType = configManager.getProperty("service.r.type");
- serviceEngineClassName = configManager.getProperty("service."
- + serviceType
- + ".class_name");
-
- // Fetch ServiceEngine from ServiceEngineFactory
- serviceEngine =
- ServiceEngineFactory.getServiceEngine(serviceEngineClassName);
+ setType(ActionType.LS_REGISTER);

}

- public String getType() {
-
- return type;
-
- }
-
-
- public void setType(String type) {
+ protected ArrayList<Message> extractMultipleRequests(Message reqMessage)
{

- this.type = type;
+ ArrayList<Message> messagesList = new ArrayList<Message>();

- }
-
- public Message execute(Message reqMessage) throws PerfSONARException {
+ //data chains container <String metadataIdRef, ArrayList<Data>>
+ HashMap<String,Message> dataChains = new HashMap<String,Message>();

- Message respMessage = null;
+ //get input data elements
+ Collection<Data> dataTriggers = reqMessage.getDataMap().values();

- try {
+ //for all data elelemtns
+ for (Data data : dataTriggers) {

- //run service engine and add result to output list
- respMessage = serviceEngine.takeAction(getType(), reqMessage);
+ //put all data having the same metadataIdRef to the same
container
+ String metaref = data.getMetadataIdRef();
+ if (dataChains.get(metaref)==null)
+ dataChains.put(metaref, new Message());
+ Message m = dataChains.get(metaref);
+ m.setData(data);
+ System.out.println("## data ["+data.getId()+"] ->
["+metaref+"]");

- } catch (PerfSONARException e) {
-
- //if an exception was thrown, convert it to result code
- //and add as a new message (to be joined) to array
-
- respMessage = ResultCodesUtil.createResultCodeMetadata(null, e) ;
-
- }
+ }

- respMessage.setId(reqMessage.getId() + "_resp");
- respMessage.setType(reqMessage.getType().replaceFirst("Request",
"Response"));
- respMessage.setMessageIdRef(reqMessage.getId());

- return respMessage;

- }
+ //for each data elements set find chaining
+ for (Map.Entry<String, Message> e : dataChains.entrySet()) {

+ try {
+
+ //get previously added message with data elements
+ Message message = e.getValue();
+
+ //get reference to metadata
+ String metadataIdRef = e.getKey();
+
+ System.out.println("## metadata chain for
["+metadataIdRef+"]");
+
+ //find metadata chaining
+ Map<String,Metadata> metadatas = new
HashMap<String,Metadata>();
+ getChaining(reqMessage, metadataIdRef, metadatas);
+ Map<String,Metadata> mergedMetadatas =
mergeAllMetadata(metadatas);
+ for (Metadata metadata : mergedMetadatas.values()) {
+ message.setMetadata(metadata);
+ }
+
+ //copy id, type from request
+ message.setId(reqMessage.getId());
+ message.setType(reqMessage.getType());
+
+ //add to result set
+ messagesList.add(message);
+
+ //temp
+ System.out.println(" --
["+message.getMetadataArray().length+"] metadatas");
+ System.out.println(" --
["+message.getDataArray().length+"] datas");
+ try {
+
System.out.println("--------------------------------------\n"+
+ XMLUtils.serializeXML(message)+
+ "--------------------------------------\n");
+ } catch (PerfSONARException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ //temp
+
+ } catch (NoSuchMetadataException e1) {
+ logger.error("LSRegisterRequest: no such metadata, cannot
find chain!");
+ }
+
+ }
+
+ return messagesList;
+
+ }
+
+
}



  • perfsonar: r2744 - branches/new-structure/trunk/perfsonar_base/src/main/java/org/perfsonar/service/base/messages, svnlog, 08/29/2007

Archive powered by MHonArc 2.6.16.

Top of Page