Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5305 - in trunk/ps-mdm-lsclient-impl: . src/main/java/org/perfsonar/ri/lsclient src/main/java/org/perfsonar/ri/lsclient/data/implementation src/main/java/org/perfsonar/ri/lsclient/data/topology src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers src/main/java/org/perfsonar/ri/lsclient/level0 src/main/java/org/perfsonar/ri/lsclient/level1 src/main/java/org/perfsonar/ri/lsclient/xml

Subject: perfsonar development work

List archive

perfsonar: r5305 - in trunk/ps-mdm-lsclient-impl: . src/main/java/org/perfsonar/ri/lsclient src/main/java/org/perfsonar/ri/lsclient/data/implementation src/main/java/org/perfsonar/ri/lsclient/data/topology src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers src/main/java/org/perfsonar/ri/lsclient/level0 src/main/java/org/perfsonar/ri/lsclient/level1 src/main/java/org/perfsonar/ri/lsclient/xml


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5305 - in trunk/ps-mdm-lsclient-impl: . src/main/java/org/perfsonar/ri/lsclient src/main/java/org/perfsonar/ri/lsclient/data/implementation src/main/java/org/perfsonar/ri/lsclient/data/topology src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers src/main/java/org/perfsonar/ri/lsclient/level0 src/main/java/org/perfsonar/ri/lsclient/level1 src/main/java/org/perfsonar/ri/lsclient/xml
  • Date: Mon, 12 Oct 2009 06:46:49 -0400

Author: krzjed
Date: 2009-10-12 06:46:49 -0400 (Mon, 12 Oct 2009)
New Revision: 5305

Modified:
trunk/ps-mdm-lsclient-impl/pom.xml

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/LookupServiceImpl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/ServiceMeasurementMetadataImpl.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/EndPointTopologyElement.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NetworkInterfaceTopologyElement.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NodeTopologyElement.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/ServiceTopologyElement.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/BufferedSoapStrippingStream.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ResponseParser.java

trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ServiceMeasurementMetadataSAXHandler.java
Log:
some bad smells removed

Modified: trunk/ps-mdm-lsclient-impl/pom.xml
===================================================================
--- trunk/ps-mdm-lsclient-impl/pom.xml 2009-10-12 09:57:50 UTC (rev 5304)
+++ trunk/ps-mdm-lsclient-impl/pom.xml 2009-10-12 10:46:49 UTC (rev 5305)
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0";
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+<project xmlns="http://maven.apache.org/POM/4.0.0";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd";>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.surfnet.perfsonar</groupId>
@@ -112,6 +111,34 @@
<groupId>org.codehaus.mojo</groupId>
<artifactId>taglist-maven-plugin</artifactId>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <linkXref>true</linkXref>
+ <sourceEncoding>utf-8</sourceEncoding>
+ <minimumTokens>100</minimumTokens>
+ <targetJdk>1.6</targetJdk>
+ <excludes>
+
<exclude>**/*Bean.java</exclude>
+
<exclude>**/generated/*.java</exclude>
+ </excludes>
+ <excludeRoots>
+
<excludeRoot>target/generated-sources/stubs</excludeRoot>
+ </excludeRoots>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>2.0.1</version>
+ <configuration>
+ <xmlOutput>true</xmlOutput>
+ <!-- Optional derectory to put
findbugs xdoc xml report -->
+
<xmlOutputDirectory>target/site</xmlOutputDirectory>
+ </configuration>
+ </plugin>
</plugins>
</reporting>

@@ -122,7 +149,7 @@
</repository>
</repositories>

- <build>
+ <build>
<pluginManagement>
<plugins>
<plugin>
@@ -136,7 +163,7 @@
<resource>
<directory>src/resources</directory>
</resource>
- </resources>
+ </resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -146,13 +173,13 @@
</configuration>
</plugin>
<plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptorRefs>
-
<descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- </plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptorRefs>
+
<descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/LsClientImpl.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -4,7 +4,6 @@
import org.perfsonar.lsclient.Level0LsClientInterface;
import org.perfsonar.lsclient.Level1LsClientInterface;
import org.perfsonar.lsclient.Level2LsClientInterface;
-import org.perfsonar.lsclient.LsClient;
import org.perfsonar.lsclient.helpers.AbstractLsClient;
import org.perfsonar.ri.lsclient.level0.Level0Impl;
import org.perfsonar.ri.lsclient.level1.Level1Impl;
@@ -16,7 +15,7 @@
* @author michael.bischoff
* @see AbstractLsClient
*/
-public class LsClientImpl extends AbstractLsClient implements LsClient {
+public class LsClientImpl extends AbstractLsClient{

protected final Logger logger = Logger.getLogger(getClass());


Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/LookupServiceImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/LookupServiceImpl.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/LookupServiceImpl.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -2,11 +2,8 @@

import java.net.URI;

-import org.perfsonar.lsclient.data.AuthorativeLookupservice;
+public class LookupServiceImpl extends ServiceImpl{

-public class LookupServiceImpl extends ServiceImpl implements
- AuthorativeLookupservice {
-
public LookupServiceImpl() {
}


Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/ServiceMeasurementMetadataImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/ServiceMeasurementMetadataImpl.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/implementation/ServiceMeasurementMetadataImpl.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -18,7 +18,7 @@
/**
* Topology elements described in xml
*/
- private Set<TopologyElement> topologyElements;
+ private volatile Set<TopologyElement> topologyElements;

/**
* XML representing
{@link
TopologyElement}(s)

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/Handler.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -1,6 +1,5 @@
package org.perfsonar.ri.lsclient.data.topology;

-import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/HandlersManager.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -6,71 +6,7 @@
import org.apache.log4j.Logger;

public class HandlersManager {
- private class ClassContainer {
- private Class<? extends SpecificTopologyElementHandler> handlerClass;
- private int priority;

- public ClassContainer(int priority,
- Class<? extends SpecificTopologyElementHandler>
handlerClass) {
- this.priority = priority;
- this.handlerClass = handlerClass;
- }
-
- public Class<? extends SpecificTopologyElementHandler>
getHandlerClass() {
- return handlerClass;
- }
-
- public int getPriority() {
- return priority;
- }
- }
-
- private class UriNameContainer {
- private String name;
- private String uri;
-
- protected UriNameContainer(String name, String uri) {
- this.name = name;
- this.uri = uri;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- UriNameContainer other = (UriNameContainer) obj;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (uri == null) {
- if (other.uri != null)
- return false;
- } else if (!uri.equals(other.uri))
- return false;
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((uri == null) ? 0 : uri.hashCode());
- return result;
- }
-
- @Override
- public String toString() {
- return "[" + uri + ":" + name + "]";
- }
- }
-
private static HandlersManager manager = new HandlersManager();

public static void addHandlerClass(

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/TopologyElementHandlerFactory.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -45,8 +45,7 @@
attributes, namespaces);
}
Constructor<? extends SpecificTopologyElementHandler> constructor;
- constructor = retrieveConstructor(uri, name, qName, attributes,
- namespaces, handlerClass);
+ constructor = retrieveConstructor(handlerClass);
if (constructor == null) {
return new UnknownTopologyElementHandler(uri, name, qName,
attributes, namespaces);
@@ -85,9 +84,8 @@
}

private static Constructor<? extends SpecificTopologyElementHandler>
retrieveConstructor(
- String uri, String name, String qName, Attributes attributes,
- Map<String, String> namespaces,
- Class<? extends SpecificTopologyElementHandler> handlerClass) {
+
+ Class<? extends SpecificTopologyElementHandler> handlerClass) {
Constructor<? extends SpecificTopologyElementHandler> constructor;
try {
constructor = handlerClass.getConstructor(Attributes.class);

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/UnknownTopologyElementHandler.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -17,7 +17,7 @@
public class UnknownTopologyElementHandler extends
SpecificTopologyElementHandler {

- private boolean finished;
+ private volatile boolean finished;
private String qName;
private UnknownTopologyElement element = new UnknownTopologyElement();;
private String xmlDescription;
@@ -52,16 +52,12 @@
@Override
public Set<GenericTopologyElement> getTopologyElements() {
if (!finished) {
- synchronized (this) {
- if (!finished) {
- xmlBuilder.append("</");
- xmlBuilder.append(qName);
- xmlBuilder.append(">");
- finished = true;
- xmlDescription = xmlBuilder.toString();
- element.setXmlDescription(xmlDescription);
- }
- }
+ xmlBuilder.append("</");
+ xmlBuilder.append(qName);
+ xmlBuilder.append(">");
+ finished = true;
+ xmlDescription = xmlBuilder.toString();
+ element.setXmlDescription(xmlDescription);
}
Set<GenericTopologyElement> set = new
HashSet<GenericTopologyElement>();
set.add(element);

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/EndPointTopologyElement.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/EndPointTopologyElement.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/EndPointTopologyElement.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -3,7 +3,6 @@
import java.net.URI;
import java.net.URISyntaxException;

-import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.topology.GenericTopologyElement;

/**

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NetworkInterfaceTopologyElement.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NetworkInterfaceTopologyElement.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NetworkInterfaceTopologyElement.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -7,7 +7,6 @@
import java.util.Map;
import java.util.Set;

-import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.topology.GenericTopologyElement;

/**

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NodeTopologyElement.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NodeTopologyElement.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/NodeTopologyElement.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -8,7 +8,6 @@
import java.util.Map;
import java.util.Set;

-import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.topology.GenericTopologyElement;
import org.perfsonar.ri.lsclient.data.topology.Port;


Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/ServiceTopologyElement.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/ServiceTopologyElement.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers/ServiceTopologyElement.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -7,7 +7,6 @@
import java.util.Map;
import java.util.Set;

-import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.topology.GenericTopologyElement;

/**

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/BufferedSoapStrippingStream.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/BufferedSoapStrippingStream.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level0/BufferedSoapStrippingStream.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -4,200 +4,203 @@
import java.io.InputStream;

/**
- * Cause the stream to be buffered as much as needed to detriment
- * if the data is part of a soap envelope. If data belonging to a
- * SOAP envelope is encountered it is discarded. (or Stripped if
- * you may)
+ * Cause the stream to be buffered as much as needed to detriment if the
data is
+ * part of a soap envelope. If data belonging to a SOAP envelope is
encountered
+ * it is discarded. (or Stripped if you may)
*
* @author michael.bischoff
*/
public class BufferedSoapStrippingStream extends InputStream {

- private final InputStream inputStream;
- private final Object bufferMutex = new Object();
- private volatile boolean closed = false;
-
- private int[] buffer = new int[1024];
- private int bufferStart = 0;
- private int bufferEnd = 0;
-
- private String soapBodyEndTag = null;
- private boolean ended = false;
-
- public BufferedSoapStrippingStream(InputStream inputStream) {
- this.inputStream = inputStream;
- }
-
+ private final InputStream inputStream;
+ private final Object bufferMutex = new Object();
+ private volatile boolean closed = false;

- @Override
- public int read() throws IOException {
- if(closed==true) throw new IOException("InputStream is
closed!");
- if(ended==true) return -1;
-
- if(!isBufferEmpty()) return popBuffer();
-
- if(soapBodyEndTag==null) return readUntillSoapBody();
- return checkForSoapBodyEnd();
- }
+ private int[] buffer = new int[1024];
+ private int bufferStart = 0;
+ private int bufferEnd = 0;

- private int checkForSoapBodyEnd() throws IOException {
- int data;
- for(int index = 0;index < soapBodyEndTag.length();index++) {
- data = readChar();
- pushBuffer(data);
- if(data != soapBodyEndTag.charAt(index)) {
- return popBuffer();
- }
- }
-
- ended=true; // needed because it should keep returning -1 in
consecutive calls
-
- while(!isBufferEmpty()) {
- popBuffer();
- }
-
- // If we get here then there is data in the buffer that
equals soapBodyEndTag
- while(inputStream.read() != -1) {
- /* skip */
- }
-
- return -1;
- }
+ private String soapBodyEndTag = null;
+ private boolean ended = false;

+ public BufferedSoapStrippingStream(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }

- /**
- * @return the fist byte in the soap body
- * @throws IOException
- */
- private int readUntillSoapBody() throws IOException {
-
- if(readChar() != '<') {
- throw new IOException("Unexpected characters in the
stream (We expected a XML decaration OR start tag here)");
- }
+ @Override
+ public int read() throws IOException {
+ if (closed == true)
+ throw new IOException("InputStream is closed!");
+ if (ended == true)
+ return -1;

- int data = readChar();
-
- if(data == '?') {
- //Skipping XML declaration
- skipTillChar('<');
- } else {
- pushBuffer(data);
- }
-
- String prefix;
- synchronized (bufferMutex) {
- pushIntoBufferTillChar(':');
- prefix = getStringFromBuffer().trim();
- }
-
-/*
- //Look for XML Namespace definition
- while(data != '=') {
- readTillString(prefix);
- // whitespace is allowed
- data = skipWhitespace();
- }
- //after = a whitespace is allowed too
- skipWhitespace();
- if(readChar()!='"') {
- throw new IOException("Atribute should be inside
quotes");
- }
- pushIntoBufferTillChar('"');
- String namespaceUri = getStringFromBuffer().trim();
-*/
- readTillString(prefix+":"+"Body");
- skipTillChar('>');
-
-
- soapBodyEndTag = "</"+prefix+":Body";
-
- return skipWhitespace();
- }
+ if (!isBufferEmpty())
+ return popBuffer();

+ if (soapBodyEndTag == null)
+ return readUntillSoapBody();
+ return checkForSoapBodyEnd();
+ }

- private void pushIntoBufferTillChar(int stopAt) throws IOException {
- int data;
- while((data = readChar()) != stopAt) {
- pushBuffer(data);
- }
- return;
- }
+ private int checkForSoapBodyEnd() throws IOException {
+ int data;
+ for (int index = 0; index < soapBodyEndTag.length(); index++) {
+ data = readChar();
+ pushBuffer(data);
+ if (data != soapBodyEndTag.charAt(index)) {
+ return popBuffer();
+ }
+ }

+ ended = true; // needed because it should keep returning -1 in
+ // consecutive calls

- private int skipWhitespace() throws IOException {
- int data;
- while(Character.isWhitespace(data = inputStream.read())) {
- /* skip data */
- }
- return data;
- }
+ while (!isBufferEmpty()) {
+ popBuffer();
+ }

+ // // If we get here then there is data in the buffer that equals
+ // soapBodyEndTag
+ // while(inputStream.read() != -1) {
+ // /* skip */
+ // }

- private void readTillString(String string) throws IOException {
- for(int index = 0;index < string.length();) {
- if(readChar() != string.charAt(index)) {
- index = 0;
- } else {
- index++;
- }
- }
- }
+ inputStream.close();

+ return -1;
+ }

- private int readChar() throws IOException {
- int i = inputStream.read();
- if(i == -1) throw new IOException("Unexpected end of stream
(soapBodyEndTag='"+soapBodyEndTag+"', isBufferEmpty='"+isBufferEmpty()+"',
buffer='"+getStringFromBuffer()+"')");
- return i;
- }
+ /**
+ * @return the fist byte in the soap body
+ * @throws IOException
+ */
+ private int readUntillSoapBody() throws IOException {

+ if (readChar() != '<') {
+ throw new IOException(
+ "Unexpected characters in the stream (We expected a XML
decaration OR start tag here)");
+ }

- private String getStringFromBuffer() throws IOException {
- synchronized (bufferMutex) {
- StringBuilder namespacePrefix = new StringBuilder();
- while(!isBufferEmpty()) {
- namespacePrefix.append((char)popBuffer());
- }
- return namespacePrefix.toString();
- }
- }
+ int data = readChar();

- private void skipTillChar(int data) throws IOException {
- while(readChar() != data) {
- /* drop char */
- }
- }
+ if (data == '?') {
+ // Skipping XML declaration
+ skipTillChar('<');
+ } else {
+ pushBuffer(data);
+ }

- @Override
- public void close() throws IOException {
- buffer = null;
- inputStream.close();
- super.close();
- }
-
- private boolean isBufferEmpty() {
- return bufferStart == bufferEnd;
- }
-
- private int popBuffer() throws IOException {
- synchronized (bufferMutex) {
- if(isBufferEmpty()) {
- throw new IOException("Buffer is empty, can't
pop buffer");
- }
- int data = buffer[bufferStart];
-
- bufferStart++;
- if(bufferStart>=buffer.length) bufferStart = 0;
-
- return data;
- }
- }
-
- private void pushBuffer(int data) {
- synchronized (bufferMutex) {
- buffer[bufferEnd] = data;
-
- bufferEnd++;
- if(bufferEnd>=buffer.length) bufferEnd = 0;
- }
- }
+ String prefix;
+ synchronized (bufferMutex) {
+ pushIntoBufferTillChar(':');
+ prefix = getStringFromBuffer().trim();
+ }
+
+ /*
+ * //Look for XML Namespace definition while(data != '=') {
+ * readTillString(prefix); // whitespace is allowed data =
+ * skipWhitespace(); } //after = a whitespace is allowed too
+ * skipWhitespace(); if(readChar()!='"') { throw new
+ * IOException("Atribute should be inside quotes"); }
+ * pushIntoBufferTillChar('"'); String namespaceUri =
+ * getStringFromBuffer().trim();
+ */
+ readTillString(prefix + ":" + "Body");
+ skipTillChar('>');
+
+ soapBodyEndTag = "</" + prefix + ":Body";
+
+ return skipWhitespace();
+ }
+
+ private void pushIntoBufferTillChar(int stopAt) throws IOException {
+ int data;
+ while ((data = readChar()) != stopAt) {
+ pushBuffer(data);
+ }
+ }
+
+ private int skipWhitespace() throws IOException {
+ int data;
+ while (true) {
+ data = inputStream.read();
+ if (!Character.isWhitespace(data)) {
+ break;
+ }
+ }
+ return data;
+ }
+
+ private void readTillString(String string) throws IOException {
+ for (int index = 0; index < string.length();) {
+ if (readChar() != string.charAt(index)) {
+ index = 0;
+ } else {
+ index++;
+ }
+ }
+ }
+
+ private int readChar() throws IOException {
+ int i = inputStream.read();
+ if (i == -1)
+ throw new IOException("Unexpected end of stream
(soapBodyEndTag='"
+ + soapBodyEndTag + "', isBufferEmpty='" + isBufferEmpty()
+ + "', buffer='" + getStringFromBuffer() + "')");
+ return i;
+ }
+
+ private String getStringFromBuffer() throws IOException {
+ synchronized (bufferMutex) {
+ StringBuilder namespacePrefix = new StringBuilder();
+ while (!isBufferEmpty()) {
+ namespacePrefix.append((char) popBuffer());
+ }
+ return namespacePrefix.toString();
+ }
+ }
+
+ private void skipTillChar(int data) throws IOException {
+ while (true) {
+ if (readChar() == data) {
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ buffer = null;
+ inputStream.close();
+ super.close();
+ }
+
+ private boolean isBufferEmpty() {
+ return bufferStart == bufferEnd;
+ }
+
+ private int popBuffer() throws IOException {
+ synchronized (bufferMutex) {
+ if (isBufferEmpty()) {
+ throw new IOException("Buffer is empty, can't pop buffer");
+ }
+ int data = buffer[bufferStart];
+
+ bufferStart++;
+ if (bufferStart >= buffer.length)
+ bufferStart = 0;
+
+ return data;
+ }
+ }
+
+ private void pushBuffer(int data) {
+ synchronized (bufferMutex) {
+ buffer[bufferEnd] = data;
+
+ bufferEnd++;
+ if (bufferEnd >= buffer.length)
+ bufferEnd = 0;
+ }
+ }
}

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -16,134 +16,132 @@
import org.perfsonar.lsclient.data.LookupService;

public class RootGlses implements Iterable<LookupService> {
- private final ConcurrentLinkedQueue<LookupService> data = new
ConcurrentLinkedQueue<LookupService>();
- private final Object timerMutex;
- private final Object mutex;
- protected volatile Timer timer;
- protected final Logger logger = Logger.getLogger(getClass());
+ private final ConcurrentLinkedQueue<LookupService> data = new
ConcurrentLinkedQueue<LookupService>();
+ private final Object timerMutex;
+ private final Object mutex;
+ protected volatile Timer timer;
+ protected final Logger logger = Logger.getLogger(getClass());

- public RootGlses() {
- this.mutex = this;
- this.timerMutex = new Object();
- }
+ public RootGlses() {
+ this.mutex = this;
+ this.timerMutex = new Object();
+ }

- public boolean isEmpty() {
- return data.isEmpty();
- }
+ public boolean isEmpty() {
+ return data.isEmpty();
+ }

- public void replace(Collection<LookupService> values) {
- synchronized (mutex) {
- // TODO speed up by using parallel requests. + add
cutoff
- // points.
- SortedMap<Long, LookupService> timedServices = new
TreeMap<Long, LookupService>();
- for (LookupService service : values) {
- try {
- URLConnection connection =
service.getEndPoint().toURL()
- .openConnection();
- connection.setConnectTimeout(2000);
// We should be able
- // to be strict here
- connection.setUseCaches(false);
- long startTime = System.nanoTime();
- connection.connect();
-
timedServices.put(Long.valueOf(System.nanoTime()
- - startTime),
service);
- } catch (MalformedURLException e) {
- logger
- .error(
-
"Supplied service endpoint('"
-
+ service.getEndPoint()
-
+ "') is not a valid URL, this client only understands http(s)",
- e);
- } catch (IOException e) {
- logger.warn("Error occoured while
trying to time gls('"
- +
service.getEndPoint() + "')", e);
- logger.info("Dropping supplied entry:
"
- +
service.getEndPoint());
- }
- }
- if (timedServices.isEmpty()) {
- logger
- .error("None of the supplied
root services where accepted. falling back to old values");
- return;
- }
- data.clear();
- data.addAll(timedServices.values());
- }
- }
+ public void replace(Collection<LookupService> values) {
+ synchronized (mutex) {
+ // TODO speed up by using parallel requests. + add cutoff
+ // points.
+ SortedMap<Long, LookupService> timedServices = new TreeMap<Long,
LookupService>();
+ for (LookupService service : values) {
+ try {
+ URLConnection connection = service.getEndPoint().toURL()
+ .openConnection();
+ connection.setConnectTimeout(2000); // We should be able
+ // to be strict here
+ connection.setUseCaches(false);
+ long startTime = System.nanoTime();
+ connection.connect();
+ timedServices.put(Long.valueOf(System.nanoTime()
+ - startTime), service);
+ } catch (MalformedURLException e) {
+ logger
+ .error(
+ "Supplied service endpoint('"
+ + service.getEndPoint()
+ + "') is not a valid URL, this
client only understands http(s)",
+ e);
+ } catch (IOException e) {
+ logger.warn("Error occoured while trying to time gls('"
+ + service.getEndPoint() + "')", e);
+ logger.info("Dropping supplied entry: "
+ + service.getEndPoint());
+ }
+ }
+ if (timedServices.isEmpty()) {
+ logger
+ .error("None of the supplied root services where
accepted. falling back to old values");
+ return;
+ }
+ data.clear();
+ data.addAll(timedServices.values());
+ }
+ }

- public Iterator<LookupService> iterator() {
- return data.iterator();
- }
+ public Iterator<LookupService> iterator() {
+ return data.iterator();
+ }

- /**
- * Demotes the service to the end of the queue and promotes the rest.
- *
- * @param service
- * @param e
- */
- public void demote(LookupService service, Exception e) {
- synchronized (mutex) {
- logger.warn("Demoting Lookup service('" +
service.getEndPoint()
- + "')", e);
- if (!data.contains(service))
- return;
- if (data.peek() == service) {
- data.add(data.poll());
- }
- }
- }
+ /**
+ * Demotes the service to the end of the queue and promotes the rest.
+ *
+ * @param service
+ * @param e
+ */
+ public void demote(LookupService service, Exception e) {
+ synchronized (mutex) {
+ logger.warn("Demoting Lookup service('" + service.getEndPoint()
+ + "')", e);
+ if (!data.contains(service))
+ return;
+ if (data.peek() == service) {
+ data.add(data.poll());
+ }
+ }
+ }

- public void ensureFilled() {
- if (data.isEmpty())
- synchronized (mutex) {
- if (data.isEmpty()) {
- fill();
- }
- }
- }
+ public void ensureFilled() {
+ if (data.isEmpty())
+ synchronized (mutex) {
+ if (data.isEmpty()) {
+ fill();
+ }
+ }
+ }

- protected void fill() {
- fill(true);
- }
+ protected void fill() {
+ fill(true);
+ }

- protected void fill(boolean autorefresh) {
- replace(getDefaultLookupServices());
- if (autorefresh) {
- if (timer == null) {
- synchronized (timerMutex) {
- if (timer == null) {
- timer = new
Timer("Ls-GlsList-refresher", true);
- timer.scheduleAtFixedRate(new
TimerTask() {
- @Override
- public void run() {
- synchronized
(this) {
- if
(timer == null)
-
return;
-
replace(getDefaultLookupServices());
- }
- }
- }, 600000, 600000);
- }
- }
- }
- }
- }
+ protected void fill(boolean autorefresh) {
+ replace(getDefaultLookupServices());
+ if (autorefresh && timer == null) {
+ synchronized (timerMutex) {
+ if (timer == null) {
+ timer = new Timer("Ls-GlsList-refresher", true);
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ synchronized (this) {
+ if (timer == null)
+ return;
+ replace(getDefaultLookupServices());
+ }
+ }
+ }, 600000, 600000);
+ }
+ }
+ }
+ }

- public void stopAutoRefresh() {
- if (timer != null) {
- synchronized (timerMutex) {
- if (timer != null) {
- logger.debug("Stopping auto-refresh
from root.hints");
- timer.cancel();
- timer = null;
- }
- }
- }
- }
+ public void stopAutoRefresh() {
+ if (timer != null) {
+ synchronized (timerMutex) {
+ if (timer != null) {
+ logger.debug("Stopping auto-refresh from root.hints");
+ timer.cancel();
+ timer = null;
+ }
+ }
+ }
+ }

- public Set<LookupService> getDefaultLookupServices() {
- logger.debug("Getting default lookupservices from
root.hints");
- RootHintsFileDownloader downloader = new
RootHintsFileDownloader();
- return downloader.getGlobalLookupServices();
- }
+ public Set<LookupService> getDefaultLookupServices() {
+ logger.debug("Getting default lookupservices from root.hints");
+ RootHintsFileDownloader downloader = new RootHintsFileDownloader();
+ return downloader.getGlobalLookupServices();
+ }
}
\ No newline at end of file

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ResponseParser.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ResponseParser.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ResponseParser.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -8,10 +8,8 @@
import javax.xml.parsers.SAXParserFactory;

import org.perfsonar.lsclient.LsQueryException;
-import org.perfsonar.lsclient.data.ServiceMeasurementMetadata;
import org.perfsonar.ri.lsclient.handlers.ServiceHandler;
import org.perfsonar.ri.lsclient.handlers.ServiceMeasurementMetadataHandler;
-import org.perfsonar.ri.lsclient.level1.LSMeasuredTopologyQuery;
import org.xml.sax.SAXException;

/**

Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ServiceMeasurementMetadataSAXHandler.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ServiceMeasurementMetadataSAXHandler.java
2009-10-12 09:57:50 UTC (rev 5304)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/xml/ServiceMeasurementMetadataSAXHandler.java
2009-10-12 10:46:49 UTC (rev 5305)
@@ -1,10 +1,8 @@
package org.perfsonar.ri.lsclient.xml;

-import java.net.NetworkInterface;
import java.util.HashMap;
import java.util.Map;

-import org.perfsonar.lsclient.LsQueryException;
import
org.perfsonar.ri.lsclient.data.implementation.ServiceMeasurementMetadataImpl;
import org.perfsonar.ri.lsclient.handlers.ServiceMeasurementMetadataHandler;
import org.perfsonar.ri.lsclient.lsinfo.Namespaces;
@@ -36,10 +34,10 @@
*/
private boolean inResultDatum;

- /**
- * Message in nmwgr:datum tag
- */
- private String resultMessage;
+ // /**
+ // * Message in nmwgr:datum tag
+ // */
+ // private String resultMessage;

/**
* Mapping of namespaces outside metadata tag
@@ -77,9 +75,10 @@
throws SAXException {
if (this.inMetadata) {
this.builder.append(ch, start, length);
- } else if (this.inResultDatum) {
- this.resultMessage = new String(ch, start, length);
}
+ // else if (this.inResultDatum) {
+ // this.resultMessage = new String(ch, start, length);
+ // }
}

/*
@@ -111,9 +110,10 @@
}
} else if (this.inResultDatum) {
if (uri.equals(Namespaces.NMWGR) && localName.equals("datum")) {
- LsQueryException exception = new LsQueryException(
- "Error occured: " + this.resultMessage);
- throw new SAXException(exception);
+ // LsQueryException exception = new LsQueryException(
+ // "Error occured: " + this.resultMessage);
+ // throw new SAXException(exception);
+ this.inResultDatum = false;
}
}
}



  • perfsonar: r5305 - in trunk/ps-mdm-lsclient-impl: . src/main/java/org/perfsonar/ri/lsclient src/main/java/org/perfsonar/ri/lsclient/data/implementation src/main/java/org/perfsonar/ri/lsclient/data/topology src/main/java/org/perfsonar/ri/lsclient/data/topology/handlers src/main/java/org/perfsonar/ri/lsclient/level0 src/main/java/org/perfsonar/ri/lsclient/level1 src/main/java/org/perfsonar/ri/lsclient/xml, svnlog, 10/12/2009

Archive powered by MHonArc 2.6.16.

Top of Page