You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2013/02/14 22:00:14 UTC
svn commit: r1446325 - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry:
./ IServicesRegistry.java ServicesRegistry.java ServicesRegistryMap.java
ServicesRegistryMapPayload.java
Author: degenaro
Date: Thu Feb 14 21:00:13 2013
New Revision: 1446325
URL: http://svn.apache.org/r1446325
Log:
UIMA-2676 DUCC webserver (WS) Services presentation improvements
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/IServicesRegistry.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMap.java
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMapPayload.java
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/IServicesRegistry.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/IServicesRegistry.java?rev=1446325&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/IServicesRegistry.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/IServicesRegistry.java Thu Feb 14 21:00:13 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.uima.ducc.ws.registry;
+
+import org.apache.uima.ducc.common.persistence.services.IStateServices;
+
+public class IServicesRegistry {
+
+ public static final String meta = IStateServices.meta;
+ public static final String svc = IStateServices.svc;
+
+ // meta
+ public static final String autostart = IStateServices.autostart;
+ public static final String endpoint = IStateServices.endpoint;
+ public static final String implementors = IStateServices.implementors;
+ public static final String instances = IStateServices.instances;
+ public static final String numeric_id = IStateServices.numeric_id;
+ public static final String user = IStateServices.user;
+
+ // svc
+ public static final String description = IStateServices.description;
+ public static final String process_memory_size = IStateServices.process_memory_size;
+ public static final String scheduling_class = IStateServices.scheduling_class;
+
+}
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java?rev=1446325&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistry.java Thu Feb 14 21:00:13 2013
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.uima.ducc.ws.registry;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.persistence.services.IStateServices;
+import org.apache.uima.ducc.common.persistence.services.StateServices;
+import org.apache.uima.ducc.common.persistence.services.StateServicesDirectory;
+import org.apache.uima.ducc.common.persistence.services.StateServicesSet;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+import org.springframework.util.StringUtils;
+
+public class ServicesRegistry {
+
+ public ServicesRegistry() {
+ refreshCache();
+ }
+
+ private ServicesRegistryMap map = new ServicesRegistryMap();
+
+ public void refreshCache() {
+ try {
+ ServicesRegistryMap mapRevised = new ServicesRegistryMap();
+ IStateServices iss = StateServices.getInstance();
+ StateServicesDirectory ssd = iss.getStateServicesDirectory();
+ if(!ssd.getDescendingKeySet().isEmpty()) {
+ for(Integer key : ssd.getDescendingKeySet()) {
+ StateServicesSet entry = ssd.get(key);
+ Properties propertiesSvc = entry.get(IServicesRegistry.svc);
+ Properties propertiesMeta = entry.get(IServicesRegistry.meta);
+ ServicesRegistryMapPayload value = new ServicesRegistryMapPayload(propertiesSvc, propertiesMeta);
+ mapRevised.put(key, value);
+ }
+ }
+ map = mapRevised;
+ }
+ catch(IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public ServicesRegistryMap getMap() {
+ return map;
+ }
+
+ public ServicesRegistryMap getCurrentMap() {
+ refreshCache();
+ return map;
+ }
+
+ public String[] getList(String string) {
+ String[] retVal = new String[0];
+ if(string != null) {
+ string = string.trim();
+ if(string.length() > 0) {
+ retVal = StringUtils.delimitedListToStringArray(string, " ");
+ }
+ }
+ return retVal;
+ }
+
+ public ArrayList<String> getArrayList(String list) {
+ ArrayList<String> retVal = new ArrayList<String>();
+ for(String string : getList(list)) {
+ retVal.add(string);
+ }
+ return retVal;
+ }
+
+ public ServicesRegistryMapPayload findService(String name) {
+ ServicesRegistryMapPayload retVal = null;
+ try {
+ for(Integer key : map.keySet()) {
+ ServicesRegistryMapPayload payload = map.get(key);
+ Properties meta = payload.meta;
+ if(meta != null) {
+ if(meta.containsKey(IServicesRegistry.endpoint)) {
+ String endpoint = meta.getProperty(IServicesRegistry.endpoint);
+ if(name.equals(endpoint)) {
+ retVal = payload;
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ return retVal;
+ }
+
+ public String findServiceName(DuccId duccId) {
+ String retVal = null;
+ try {
+ long id = duccId.getFriendly();
+ for(Integer key : map.keySet()) {
+ ServicesRegistryMapPayload payload = map.get(key);
+ Properties meta = payload.meta;
+ if(meta != null) {
+ String implementors = meta.getProperty(IServicesRegistry.implementors);
+ String[] list = getList(implementors);
+ for( String member : list ) {
+ if(member.equals(id+"")) {
+ if(meta.containsKey(IServicesRegistry.endpoint)) {
+ retVal = meta.getProperty(IServicesRegistry.endpoint);
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ return retVal;
+ }
+
+ /*
+
+ public static ServicesRegistry sr = new ServicesRegistry();
+
+ public static void test(long id) {
+ DuccId duccId = new DuccId(id);
+ String name = sr.findServiceName(duccId);
+ if(name == null) {
+ System.out.println(id+" not found");
+ }
+ else {
+ System.out.println(id+" => "+name);
+ }
+ }
+
+ public static void main(String[] args) {
+ test(3);
+ test(9);
+ }
+ */
+}
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMap.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMap.java?rev=1446325&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMap.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMap.java Thu Feb 14 21:00:13 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.uima.ducc.ws.registry;
+
+import java.util.Iterator;
+import java.util.NavigableSet;
+import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ServicesRegistryMap extends ConcurrentHashMap<Integer,ServicesRegistryMapPayload> {
+
+ private static final long serialVersionUID = 1L;
+
+ public NavigableSet<Integer> getDescendingKeySet() {
+ TreeMap<Integer,ServicesRegistryMapPayload> tMap = new TreeMap<Integer,ServicesRegistryMapPayload>();
+ Iterator<java.util.Map.Entry<Integer, ServicesRegistryMapPayload>> iterator = entrySet().iterator();
+ while(iterator.hasNext()) {
+ java.util.Map.Entry<Integer, ServicesRegistryMapPayload> entry = iterator.next();
+ tMap.put(entry.getKey(), entry.getValue());
+ }
+ return tMap.descendingKeySet();
+ }
+}
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMapPayload.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMapPayload.java?rev=1446325&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMapPayload.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/registry/ServicesRegistryMapPayload.java Thu Feb 14 21:00:13 2013
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.uima.ducc.ws.registry;
+
+import java.util.Properties;
+
+import org.apache.uima.ducc.common.persistence.services.IStateServices;
+
+public class ServicesRegistryMapPayload {
+
+ public Properties svc;
+ public Properties meta;
+
+ public ServicesRegistryMapPayload(Properties svc, Properties meta) {
+ this.svc = svc;
+ this.meta = meta;
+ }
+
+ public Properties get(String key) {
+ Properties retVal = null;
+ if(key != null) {
+ if(key.equals(IStateServices.svc)) {
+ retVal = svc;
+ }
+ else if(key.equals(IStateServices.meta)) {
+ retVal = meta;
+ }
+ }
+ return retVal;
+ }
+}