You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2007/02/26 03:01:46 UTC

svn commit: r511692 - /webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java

Author: danj
Date: Sun Feb 25 18:01:45 2007
New Revision: 511692

URL: http://svn.apache.org/viewvc?view=rev&rev=511692
Log:
Fix for MUSE-200

Added:
    webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java

Added: webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java?view=auto&rev=511692
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java (added)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-impl/src/org/apache/muse/ws/dm/muws/remote/MetricsClient.java Sun Feb 25 18:01:45 2007
@@ -0,0 +1,134 @@
+/*=============================================================================*
+ *  Copyright 2007 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.ws.dm.muws.remote;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.Environment;
+import org.apache.muse.util.xml.XsdUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapClient;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.dm.muws.MuwsConstants;
+import org.apache.muse.ws.resource.properties.impl.WsrpUtils;
+import org.apache.muse.ws.resource.remote.WsResourceClient;
+
+/**
+ *
+ * MetricsClient provides two convenience methods for reading WSRP resource 
+ * properties and their metrics without resorting to separate SOAP calls or 
+ * DOM APIs. The user can provide a java.util.Map that will be filled with 
+ * the metric data in POJO form.
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class MetricsClient extends WsResourceClient
+{
+    public MetricsClient(EndpointReference destination)
+    {
+        super(destination);
+    }
+    
+    public MetricsClient(EndpointReference destination, EndpointReference source)
+    {
+        super(destination, source);
+    }
+    
+    public MetricsClient(EndpointReference destination, EndpointReference source, Environment environment)
+    {
+        super(destination, source, environment);
+    }
+    
+    public MetricsClient(EndpointReference destination, EndpointReference source, SoapClient soapClient)
+    {
+        super(destination, source, soapClient);
+    }
+    
+    /**
+     * 
+     * This method is just like getPropertyAsObject() except that it will fill 
+     * the given Map with the metrics returned in the property XML. The ResetAt 
+     * metric (MuwsConstants.RESET_AT) is a java.util.Date, the LastUpdated 
+     * metrics (MuwsConstants.LAST_UPDATED) is a java.util.Date, and the Duration 
+     * metric (MuwsConstants.DURATION) is a java.lang.String. If there were no 
+     * property values, the Map will not be modified.
+     * 
+     */
+    public Object getPropertyAsObjectAndMetrics(QName qname, Class type, Map metrics)
+        throws SoapFault
+    {
+        Element[] properties = getResourcePropertyAndMetrics(qname, metrics);
+        return WsrpUtils.convertToObjects(properties, type);
+    }
+    
+    /**
+     * 
+     * This method is just like getResourceProperty() except that it will fill 
+     * the given Map with the metrics returned in the property XML. The ResetAt 
+     * metric (MuwsConstants.RESET_AT) is a java.util.Date, the LastUpdated 
+     * metrics (MuwsConstants.LAST_UPDATED) is a java.util.Date, and the Duration 
+     * metric (MuwsConstants.DURATION) is a java.lang.String. If there were no 
+     * property values, the Map will not be modified.
+     * 
+     * @see MuwsConstants
+     * 
+     */
+    public Element[] getResourcePropertyAndMetrics(QName qname, Map metrics)
+        throws SoapFault
+    {
+        Element[] properties = super.getResourceProperty(qname);
+        
+        //
+        // assuming there were some values, we only need to read the metrics 
+        // from one of the elements - they all have the same metric values
+        //
+        if (properties.length > 0)
+        {
+            String resetAt = properties[0].getAttribute(MuwsConstants.RESET_AT);
+            String lastUpdated = properties[0].getAttribute(MuwsConstants.LAST_UPDATED);
+            String duration = properties[0].getAttribute(MuwsConstants.DURATION);
+            
+            //
+            // need to return ResetAt and LastUpdated as java.util.Date
+            //
+            try
+            {
+                if (resetAt != null)
+                    metrics.put(MuwsConstants.RESET_AT, XsdUtils.getLocalTime(resetAt));
+            
+                if (lastUpdated != null)
+                    metrics.put(MuwsConstants.LAST_UPDATED, XsdUtils.getLocalTime(lastUpdated));
+            }
+            
+            catch (Throwable error)
+            {
+                throw new SoapFault(error.getMessage(), error);
+            }
+            
+            if (duration != null)
+                metrics.put(MuwsConstants.DURATION, duration);
+        }
+        
+        return properties;
+    }    
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org