jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1488536 - in /jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki: mgt/ migrate/ server/ servlets/
Date Sat, 01 Jun 2013 15:28:11 GMT
Author: andy
Date: Sat Jun  1 15:28:11 2013
New Revision: 1488536

URL: http://svn.apache.org/r1488536
Log:
Counters for all operations.
JMX support + JSON output via mgt interface.

Added:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/StatsServlet.java
      - copied, changed from r1487878, jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/StatsServlet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterMXBean.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetMXBean.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceMXBean.java
Removed:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/StatsServlet.java
Modified:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionDataset.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ManagementServer.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/MgtCmdServlet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/migrate/Registry.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterName.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterSet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceRef.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionDataset.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionDataset.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionDataset.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionDataset.java Sat
Jun  1 15:28:11 2013
@@ -20,7 +20,6 @@ package org.apache.jena.fuseki.mgt;
 
 import java.io.IOException ;
 import java.io.UnsupportedEncodingException ;
-import java.util.Iterator ;
 
 import javax.servlet.ServletOutputStream ;
 import javax.servlet.http.HttpServlet ;
@@ -69,10 +68,7 @@ public class ActionDataset extends HttpS
             ServletOutputStream out = response.getOutputStream() ;
             out.print("<p>"+dataset+"("+known+")</p>") ;
 
-            Iterator<String> iter = DatasetRegistry.get().keys() ;
-            for ( ; iter.hasNext() ; )
-            {
-                String name = iter.next() ;
+            for ( String name : DatasetRegistry.get().keys() ) {
                 out.print("<li>") ;
                 out.print(name) ;
                 out.println("</li>") ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ManagementServer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ManagementServer.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ManagementServer.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ManagementServer.java
Sat Jun  1 15:28:11 2013
@@ -27,28 +27,28 @@ import javax.servlet.http.HttpServlet ;
 import org.apache.jena.fuseki.Fuseki ;
 import org.apache.jena.fuseki.server.FusekiErrorHandler ;
 import org.apache.jena.fuseki.servlets.DumpServlet ;
-import org.apache.jena.fuseki.servlets.StatsServlet ;
 import org.eclipse.jetty.server.Connector ;
 import org.eclipse.jetty.server.Server ;
-import org.eclipse.jetty.server.nio.BlockingChannelConnector ;
+import org.eclipse.jetty.server.nio.SelectChannelConnector ;
 import org.eclipse.jetty.servlet.ServletContextHandler ;
 import org.eclipse.jetty.servlet.ServletHolder ;
 
 public class ManagementServer
 {
-
     public static Server createManagementServer(int mgtPort)
     {
         Fuseki.serverLog.info("Adding management functions") ;
-        // This is actually a separate Jetty server
-        Server server = new Server() ;
         
-        BlockingChannelConnector bcConnector = new BlockingChannelConnector() ;
-        //bcConnector.setUseDirectBuffers(false) ;
+        // Separate Jetty server
+        Server server = new Server() ;
         
-        Connector connector = bcConnector ;
-        // Ignore. If set, then if this goes off, it keeps going off 
-        // and you get a lot of log messages.
+//        BlockingChannelConnector bcConnector = new BlockingChannelConnector() ;
+//        bcConnector.setUseDirectBuffers(false) ;
+//        Connector connector = bcConnector ;
+        
+        Connector connector = new SelectChannelConnector() ;
+        // Ignore idle time. 
+        // If set, then if this goes off, it keeps going off and you get a lot of log messages.
         connector.setMaxIdleTime(0) ; // Jetty outputs a lot of messages if this goes off.
         connector.setPort(mgtPort);
         server.addConnector(connector) ;
@@ -67,8 +67,6 @@ public class ManagementServer
 //      // Development : server control panel.
 //      addServlet(context, new ServerServlet(), "/server") ;
 //      addServlet(context, new ActionBackup(), "/backup") ;
-
-        
     }
 
     // SHARE

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/MgtCmdServlet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/MgtCmdServlet.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/MgtCmdServlet.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/MgtCmdServlet.java Sat
Jun  1 15:28:11 2013
@@ -45,6 +45,7 @@ import com.hp.hpl.jena.tdb.TDB ;
 
 public class MgtCmdServlet extends HttpServlet
 {
+    // Experimental - likely to change. 
     private static Logger log = Fuseki.serverLog ;
 
     public MgtCmdServlet()
@@ -61,8 +62,7 @@ public class MgtCmdServlet extends HttpS
     public static String paramCmd     = "cmd" ;
     public static String cmdBackup    = "backup" ;          // &dataset=/datasetname
     public static String cmdRestart   = "restart" ;         // Not implemented.
-    public static String cmdShutdown  = "shutdown" ;        // Server stops, no
-                                                            // questions asked.
+    public static String cmdShutdown  = "shutdown" ;        // Server stops, no questions
asked. (Not implemented)
 
     ActionBackup         actionBackup = new ActionBackup() ;
 

Copied: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/StatsServlet.java
(from r1487878, jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/StatsServlet.java)
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/StatsServlet.java?p2=jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/StatsServlet.java&p1=jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/StatsServlet.java&r1=1487878&r2=1488536&rev=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/StatsServlet.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/StatsServlet.java Sat
Jun  1 15:28:11 2013
@@ -16,19 +16,20 @@
  * limitations under the License.
  */
 
-package org.apache.jena.fuseki.servlets;
+package org.apache.jena.fuseki.mgt;
 
 import java.io.IOException ;
-import java.io.PrintWriter ;
 import java.util.Iterator ;
 
+import javax.servlet.ServletOutputStream ;
 import javax.servlet.http.HttpServlet ;
 import javax.servlet.http.HttpServletRequest ;
 import javax.servlet.http.HttpServletResponse ;
 
-import org.apache.jena.fuseki.server.CounterName ;
-import org.apache.jena.fuseki.server.DatasetRef ;
-import org.apache.jena.fuseki.server.DatasetRegistry ;
+import org.apache.jena.atlas.json.JSON ;
+import org.apache.jena.atlas.json.JsonObject ;
+import org.apache.jena.fuseki.server.* ;
+import org.apache.jena.riot.WebContent ;
 
 public class StatsServlet extends HttpServlet
 {
@@ -37,25 +38,83 @@ public class StatsServlet extends HttpSe
         //throws ServletException, IOException
     {
         try {
-            PrintWriter out = resp.getWriter() ;
-            resp.setContentType("text/plain");
-            
-            Iterator<String> iter = DatasetRegistry.get().keys() ;
-            while(iter.hasNext())
-            {
-                String ds = iter.next() ;
-                DatasetRef desc = DatasetRegistry.get().get(ds) ;
-                stats(out, desc) ;
-                if ( iter.hasNext() )
-                    out.println() ;
-            }
-            
-            out.flush() ;
+            // Conneg etc.
+            statsJSON(req, resp) ;
         } catch (IOException e)
         { }
     }
     
-    private void stats(PrintWriter out, DatasetRef desc)
+    private void statsJSON(HttpServletRequest req, HttpServletResponse resp) throws IOException
+    {
+        ServletOutputStream out = resp.getOutputStream() ;
+        resp.setContentType(WebContent.contentTypeJSON);
+        resp.setCharacterEncoding(WebContent.charsetUTF8) ;
+
+        /*
+         * { "server" : ....   
+         *    "datasets" : {
+         *       "ds1": { counters... }
+         *       GSP stucture?
+         *         
+         */
+        
+        JsonObject obj = new JsonObject() ;
+        JsonObject datasets = new JsonObject() ;
+        JsonObject server = new JsonObject() ;
+        server.put("host", req.getLocalName()+":"+req.getLocalPort()) ;
+        
+        for ( String ds : DatasetRegistry.get().keys() )
+            statsJSON(datasets, ds) ; 
+        
+        obj.put("server", server) ;
+        obj.put("datasets", datasets) ;
+        
+        JSON.write(out, obj) ;
+        out.flush() ;
+    }
+    
+    private void statsJSON(JsonObject datasets, String ds) {
+        DatasetRef desc = DatasetRegistry.get().get(ds) ;
+        JsonObject stats = new JsonObject() ;
+        datasets.put(ds, stats) ;
+        stats.put(CounterName.Requests.name(),      desc.counters.value(CounterName.Requests))
;
+        stats.put(CounterName.RequestsGood.name(),  desc.counters.value(CounterName.RequestsGood))
;
+        stats.put(CounterName.RequestsBad.name(),   desc.counters.value(CounterName.RequestsBad))
;
+        JsonObject endpoints = new JsonObject() ;
+        for ( String endpoint : desc.getEndpoints() ) {
+            ServiceRef srvRef = desc.getServiceRef(endpoint) ;
+            JsonObject epStats = new JsonObject() ;
+            statsJSON(epStats, srvRef) ;
+            endpoints.put(endpoint, epStats) ;
+        }
+        stats.put("endpoints", endpoints) ;
+    }
+
+    private void statsJSON(JsonObject epStats, ServiceRef srvRef) {
+        for (CounterName cn : srvRef.counters.counters()) {
+            Counter c = srvRef.counters.get(cn) ;
+            epStats.put(cn.name(), c.value()) ;
+        }
+    }
+
+    private void statsTxt(HttpServletResponse resp) throws IOException
+    {
+        ServletOutputStream out = resp.getOutputStream() ;
+        resp.setContentType(WebContent.contentTypeTextPlain);
+        resp.setCharacterEncoding(WebContent.charsetUTF8) ;
+
+        Iterator<String> iter = DatasetRegistry.get().keys().iterator() ;
+        while(iter.hasNext())
+        {
+            String ds = iter.next() ;
+            DatasetRef desc = DatasetRegistry.get().get(ds) ;
+            statsTxt(out, desc) ;
+            if ( iter.hasNext() )
+                out.println() ;
+        }
+        out.flush() ;
+    }
+    private void statsTxt(ServletOutputStream out, DatasetRef desc) throws IOException
     {
         out.println("Dataset: "+desc.name) ;
         out.println("    Requests      = "+desc.counters.value(CounterName.Requests)) ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/migrate/Registry.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/migrate/Registry.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/migrate/Registry.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/migrate/Registry.java Sat
Jun  1 15:28:11 2013
@@ -18,8 +18,8 @@
 
 package org.apache.jena.fuseki.migrate;
 
+import java.util.Collection ;
 import java.util.HashMap ;
-import java.util.Iterator ;
 import java.util.Map ;
 
 public class Registry<T>
@@ -34,7 +34,8 @@ public class Registry<T>
     
     public boolean isRegistered(String key) { return registry.containsKey(key) ; }
     public void remove(String key) { registry.remove(key) ; } 
-    public Iterator<String> keys() { return registry.keySet().iterator() ; }
+    public Collection<String> keys() { return registry.keySet() ; }
+    //public Iterator<String> keys() { return registry.keySet().iterator() ; }
     
     public int size() { return registry.size() ; }
     public boolean isEmpty() { return registry.isEmpty() ; }

Added: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterMXBean.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterMXBean.java?rev=1488536&view=auto
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterMXBean.java
(added)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterMXBean.java
Sat Jun  1 15:28:11 2013
@@ -0,0 +1,25 @@
+/**
+ * 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.jena.fuseki.server;
+
+public interface CounterMXBean
+{
+    long getValue() ; 
+}
+

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterName.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterName.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterName.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterName.java Sat
Jun  1 15:28:11 2013
@@ -46,11 +46,6 @@ public enum CounterName {
     
     // Graph Store Protocol.
 
-//    // Total operations.
-//    GSPrequests("gsp.requests") ,
-//    GSPrequestsGood("gsp.requests.good") ,
-//    GSPrequestsBad("gsp.requests.bad") ,
-
     // For each HTTP method
     GSPget("gsp.get.requests") ,
     GSPgetGood("gsp.get.requests.good") ,
@@ -76,6 +71,9 @@ public enum CounterName {
     GSPpatchGood("gsp.patch.requests.good") ,
     GSPpatchBad("gsp.patch.requests.bad") ,
 
+    GSPoptions("gsp.options.requests") ,
+    GSPoptionsGood("gsp.options.requests.good") ,
+    GSPoptionsBad("gsp.options.requests.bad") ,
     
     ;
     

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterSet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterSet.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterSet.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/CounterSet.java Sat
Jun  1 15:28:11 2013
@@ -18,6 +18,7 @@
 
 package org.apache.jena.fuseki.server;
 
+import java.util.Collection ;
 import java.util.HashMap ;
 import java.util.Map ;
 
@@ -32,10 +33,13 @@ public class CounterSet
     private Map<CounterName, Counter> counters = new HashMap<CounterName, Counter>()
;
     
     public CounterSet()    {}
+
+    public Collection<CounterName> counters()
+    { return counters.keySet() ; }
     
-    public void inc(CounterName c)   { get(c).inc() ; } 
-    public void dec(CounterName c)   { get(c).dec() ; } 
-    public long value(CounterName c) { return get(c).value() ; }
+    public void inc(CounterName c)          { get(c).inc() ; } 
+    public void dec(CounterName c)          { get(c).dec() ; } 
+    public long value(CounterName c)        { return get(c).value() ; }
 
     public void add(CounterName counterName) {
         if ( counters.containsKey(counterName) ) {
@@ -45,7 +49,7 @@ public class CounterSet
         counters.put(counterName, new Counter()) ;
     }
     
-    private Counter get(CounterName cn) {
+    public Counter get(CounterName cn) {
         Counter c = counters.get(cn) ; 
         if ( c == null )
             log.warn("No counter in counter set: "+cn) ;

Added: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetMXBean.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetMXBean.java?rev=1488536&view=auto
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetMXBean.java
(added)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetMXBean.java
Sat Jun  1 15:28:11 2013
@@ -0,0 +1,35 @@
+/**
+ * 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.jena.fuseki.server;
+
+public interface DatasetMXBean
+{
+    String getName() ;
+    
+    long getRequests() ;
+    long getRequestsGood() ;
+    long getRequestsBad() ;
+    
+//    void enable() ;
+//    void disable() ;
+//    void setReadOnly() ;
+//    boolean getReadOnly() ;
+    
+}
+

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java Sat
Jun  1 15:28:11 2013
@@ -18,8 +18,7 @@
 
 package org.apache.jena.fuseki.server;
 
-import java.util.HashMap ;
-import java.util.Map ;
+import java.util.* ;
 import java.util.concurrent.atomic.AtomicLong ;
 
 import org.apache.jena.fuseki.Fuseki ;
@@ -27,7 +26,7 @@ import org.apache.jena.fuseki.Fuseki ;
 import com.hp.hpl.jena.query.ReadWrite ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 
-public class DatasetRef
+public class DatasetRef implements DatasetMXBean
 {
     public String name                          = null ;
     public DatasetGraph dataset                 = null ;
@@ -37,10 +36,10 @@ public class DatasetRef
     public ServiceRef upload                    = new ServiceRef("upload") ;
     public ServiceRef readGraphStore            = new ServiceRef("gspRead") ;
     public ServiceRef readWriteGraphStore       = new ServiceRef("gspReadWrite") ; 
-
+    
     // Dataset-level counters.
     public final CounterSet counters            = new CounterSet() ;
-    private Map<String, ServiceRef> serviceRefs = new HashMap<String, ServiceRef>()
;
+    private Map<String, ServiceRef> endpoints   = new HashMap<String, ServiceRef>()
;
     private boolean initialized = false ;
     
     // Two step initiation (c.f. Builder pattern)
@@ -54,11 +53,11 @@ public class DatasetRef
     }
     
     private void initServices() {
-        add(serviceRefs, query) ;
-        add(serviceRefs, update) ;
-        add(serviceRefs, upload) ;
-        add(serviceRefs, readGraphStore) ;
-        add(serviceRefs, readWriteGraphStore) ;
+        add(endpoints, query) ;
+        add(endpoints, update) ;
+        add(endpoints, upload) ;
+        add(endpoints, readGraphStore) ;
+        add(endpoints, readWriteGraphStore) ;
     }
     
     private static void add(Map<String, ServiceRef> serviceRefs, ServiceRef srvRef)
@@ -72,7 +71,11 @@ public class DatasetRef
             Fuseki.serverLog.error("Not initialized: dataset = "+name) ;
         if ( service.startsWith("/") )
             service = service.substring(1, service.length()) ; 
-        return serviceRefs.get(service) ;
+        return endpoints.get(service) ;
+    }
+
+    public Collection<String> getEndpoints() {
+        return endpoints.keySet() ;
     }
 
     /** Counter of active read transactions */
@@ -147,4 +150,21 @@ public class DatasetRef
                ! readWriteGraphStore.isActive()
                ;
     }
+    
+    // MBean
+    
+    @Override
+    public String getName()     { return name ; }
+
+    @Override public long getRequests() { 
+        return counters.value(CounterName.Requests) ;
+    }
+    @Override
+    public long getRequestsGood() {
+        return counters.value(CounterName.RequestsGood) ;
+    }
+    @Override
+    public long getRequestsBad() {
+        return counters.value(CounterName.RequestsBad) ;
+    }
 }

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java Sat
Jun  1 15:28:11 2013
@@ -45,11 +45,10 @@ import org.eclipse.jetty.server.nio.Bloc
 import org.eclipse.jetty.servlet.DefaultServlet ;
 import org.eclipse.jetty.servlet.ServletContextHandler ;
 import org.eclipse.jetty.servlet.ServletHolder ;
+import org.eclipse.jetty.servlets.GzipFilter ;
 import org.eclipse.jetty.xml.XmlConfiguration ;
 
-import org.eclipse.jetty.servlets.GzipFilter;
-
-
+import com.hp.hpl.jena.sparql.mgt.ARQMgt ;
 import com.hp.hpl.jena.sparql.util.Utils ;
 
 public class SPARQLServer
@@ -188,7 +187,6 @@ public class SPARQLServer
             HttpServlet validateData = new DataValidator() ;    
             HttpServlet validateIRI = new IRIValidator() ;
             
-            HttpServlet statsService = new StatsServlet() ;
             HttpServlet dumpService = new DumpServlet() ;
             HttpServlet generalQueryService = new SPARQL_QueryGeneral() ;
             // TODO Name management 
@@ -209,7 +207,6 @@ public class SPARQLServer
         }
         
         return context ; 
-        
     }
     
     // Experimental - off by default.
@@ -231,7 +228,7 @@ public class SPARQLServer
         
         addCounters(dsDesc) ;
         dsDesc.init() ;
-        
+
         DatasetRegistry.get().put(datasetPath, dsDesc) ;
         serverLog.info(format("Dataset path = %s", datasetPath)) ;
         
@@ -264,6 +261,17 @@ public class SPARQLServer
             // on to the service (this takes precedence over direct naming).
             addServlet(context, datasetPath, sparqlDataset, epDataset, enableCompression)
;
         }
+        
+        // JMX
+        String x = dsDesc.name ;
+//        if ( x.startsWith("/") )
+//            x = x.substring(1) ;
+        ARQMgt.register(Fuseki.PATH+".dataset:name="+x, dsDesc) ;
+        // For all endpoints 
+        for ( String endpoint : dsDesc.getEndpoints() ) {
+            ServiceRef sRef = dsDesc.getServiceRef(endpoint) ;
+            ARQMgt.register(Fuseki.PATH+".dataset:name="+x+"/"+endpoint, sRef) ;
+        }
     }
     
     private static Server configServer(String jettyConfig)
@@ -391,8 +399,9 @@ public class SPARQLServer
         sDesc.upload.counters.add(CounterName.RequestsGood) ;
         sDesc.upload.counters.add(CounterName.RequestsBad) ; 
         
-        addCountersForGSP(sDesc.readGraphStore.counters, true) ;
         addCountersForGSP(sDesc.readWriteGraphStore.counters, false) ;
+        if ( sDesc.readGraphStore != sDesc.readGraphStore )
+            addCountersForGSP(sDesc.readGraphStore.counters, true) ;
     }
 
     private static void addCountersForGSP(CounterSet cs, boolean readWrite) {
@@ -427,6 +436,10 @@ public class SPARQLServer
         cs.add(CounterName.GSPpatch) ;
         cs.add(CounterName.GSPpatchGood) ;
         cs.add(CounterName.GSPpatchBad) ;
+
+        cs.add(CounterName.GSPoptions) ;
+        cs.add(CounterName.GSPoptionsGood) ;
+        cs.add(CounterName.GSPoptionsBad) ;
     }
 
 }

Added: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceMXBean.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceMXBean.java?rev=1488536&view=auto
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceMXBean.java
(added)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceMXBean.java
Sat Jun  1 15:28:11 2013
@@ -0,0 +1,32 @@
+/**
+ * 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.jena.fuseki.server;
+
+public interface ServiceMXBean
+{
+    String getName() ;
+    
+    long getRequests() ;
+    long getRequestsGood() ;
+    long getRequestsBad() ;
+    
+//    void enable() ;
+//    void disable() ;
+}
+

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceRef.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceRef.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceRef.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/ServiceRef.java Sat
Jun  1 15:28:11 2013
@@ -22,7 +22,7 @@ import java.util.ArrayList ;
 import java.util.List ;
 
 /** Configuration of an individual service */
-public class ServiceRef
+public class ServiceRef implements ServiceMXBean
 {
     public final String name ;
     // Service-level counters.
@@ -41,5 +41,20 @@ public class ServiceRef
     }
     
     public boolean isActive() { return endpoints.isEmpty() ; }
+
+    @Override
+    public String getName()     { return name ; }
+
+    @Override public long getRequests() { 
+        return counters.value(CounterName.Requests) ;
+    }
+    @Override
+    public long getRequestsGood() {
+        return counters.value(CounterName.RequestsGood) ;
+    }
+    @Override
+    public long getRequestsBad() {
+        return counters.value(CounterName.RequestsBad) ;
+    }
 }
 

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
Sat Jun  1 15:28:11 2013
@@ -42,6 +42,7 @@ import javax.servlet.http.HttpServletRes
 import org.apache.jena.atlas.web.ContentType ;
 import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
+import org.apache.jena.fuseki.server.CounterName ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RiotException ;
 import org.apache.jena.riot.RiotReader ;
@@ -66,17 +67,15 @@ public abstract class SPARQL_REST extend
     
     protected static ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(log)
;
 
-    protected final static Target determineTarget(HttpAction action) 
-    {
+    protected final static Target determineTarget(HttpAction action) {
         // Delayed until inside a transaction.
         if ( action.getActiveDSG() == null )
-                errorOccurred("Internal error : No action graph (not in a transaction?)")
;
+            errorOccurred("Internal error : No action graph (not in a transaction?)") ;
         
         boolean dftGraph = getOneOnly(action.request, HttpNames.paramGraphDefault) != null
;
         String uri = getOneOnly(action.request, HttpNames.paramGraph) ;
         
-        if ( !dftGraph && uri == null )
-        {
+        if ( !dftGraph && uri == null ) {
             // Direct naming or error.
             uri = action.request.getRequestURL().toString() ;
             if ( action.request.getRequestURI().equals(action.getDatasetRef().name) )
@@ -114,18 +113,15 @@ public abstract class SPARQL_REST extend
         final String name ;
         final Node graphName ;
 
-        static Target createNamed(DatasetGraph dsg, String name, Node graphName)
-        {
+        static Target createNamed(DatasetGraph dsg, String name, Node graphName) {
             return new Target(false, dsg, name, graphName) ;
         }
 
-        static Target createDefault(DatasetGraph dsg)
-        {
+        static Target createDefault(DatasetGraph dsg) {
             return new Target(true, dsg, null, null) ;
         }
 
-        private Target(boolean isDefault, DatasetGraph dsg, String name, Node graphName)
-        {
+        private Target(boolean isDefault, DatasetGraph dsg, String name, Node graphName)
{
             this.isDefault = isDefault ;
             this.dsg = dsg ;
             this._graph = null ;
@@ -145,8 +141,7 @@ public abstract class SPARQL_REST extend
         }
 
         /** Get a graph for the action - this may create a graph in the dataset - this is
not a test for graph existence */
-        public Graph graph()
-        {
+        public Graph graph() {
             if ( ! isGraphSet() )
             {
                 if ( isDefault ) 
@@ -183,54 +178,126 @@ public abstract class SPARQL_REST extend
     { this(false) ; }
 
     @Override
-    protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
-    {
+    protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
         // Direct all verbs to our common framework.
         doCommon(request, response) ;
     }
     
-    private void maybeSetLastModified(HttpServletResponse resp, long lastModified)
-    {
+    private void maybeSetLastModified(HttpServletResponse resp, long lastModified) {
         if (resp.containsHeader(HEADER_LASTMOD)) return ;
         if (lastModified >= 0) resp.setDateHeader(HEADER_LASTMOD, lastModified);
     }
     
     @Override
-    protected void perform(HttpAction action)
-    {
+    protected void perform(HttpAction action) {
         dispatch(action) ;
     }
 
-    private void dispatch(HttpAction action)
-    {
+    private void dispatch(HttpAction action) {
         HttpServletRequest req = action.request ;
         HttpServletResponse resp = action.response ;
         String method = req.getMethod().toUpperCase(Locale.ENGLISH) ;
 
-        // See HttpServlet.service.
-        // We dispatch by REQUEST
-        
         if (method.equals(METHOD_GET))
-            doGet(action);
+            doGet$(action);
         else if (method.equals(METHOD_HEAD))
-            doHead(action);
+            doHead$(action);
         else if (method.equals(METHOD_POST))
-            doPost(action);
+            doPost$(action);
         else if (method.equals(METHOD_PATCH))
-            doPatch(action) ;
+            doPatch$(action) ;
         else if (method.equals(METHOD_OPTIONS))
-            doOptions(action) ;
+            doOptions$(action) ;
         else if (method.equals(METHOD_TRACE))
             //doTrace(action) ;
             errorMethodNotAllowed("TRACE") ;
         else if (method.equals(METHOD_PUT))
-            doPut(action) ;   
+            doPut$(action) ;   
         else if (method.equals(METHOD_DELETE))
-            doDelete(action) ;
+            doDelete$(action) ;
         else
             errorNotImplemented("Unknown method: "+method) ;
     }
-        
+
+    // Counter wrappers
+    
+    protected void doGet$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPget) ;
+        try {
+            doGet(action) ;
+            action.srvRef.counters.inc(CounterName.GSPgetGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPgetBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doHead$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPhead) ;
+        try {
+            doHead(action) ;
+            action.srvRef.counters.inc(CounterName.GSPheadGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPheadBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doPost$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPpost) ;
+        try {
+            doPost(action) ;
+            action.srvRef.counters.inc(CounterName.GSPpostGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPpostBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doPatch$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPpatch) ;
+        try {
+            doPatch(action) ;
+            action.srvRef.counters.inc(CounterName.GSPpatchGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPpatchBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doDelete$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPdelete) ;
+        try {
+            doDelete(action) ;
+            action.srvRef.counters.inc(CounterName.GSPdeleteGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPdeleteBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doPut$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPput) ;
+        try {
+            doPut(action) ;
+            action.srvRef.counters.inc(CounterName.GSPputGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPputBad) ;
+            throw ex ;
+        }
+    }
+
+    protected void doOptions$(HttpAction action) {
+        action.srvRef.counters.inc(CounterName.GSPoptions) ;
+        try {
+            doOptions(action) ;
+            action.srvRef.counters.inc(CounterName.GSPoptionsGood) ;
+        } catch ( ActionErrorException ex) {
+            action.srvRef.counters.inc(CounterName.GSPoptionsBad) ;
+            throw ex ;
+        }
+    }
+    
     protected abstract void doGet(HttpAction action) ;
     protected abstract void doHead(HttpAction action) ;
     protected abstract void doPost(HttpAction action) ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java?rev=1488536&r1=1488535&r2=1488536&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java
Sat Jun  1 15:28:11 2013
@@ -19,10 +19,12 @@
 package org.apache.jena.fuseki.servlets;
 
 import static java.lang.String.format ;
+import static org.apache.jena.fuseki.server.CounterName.Requests ;
+import static org.apache.jena.fuseki.server.CounterName.RequestsBad ;
+import static org.apache.jena.fuseki.server.CounterName.RequestsGood ;
 
 import java.io.IOException ;
 import java.util.Enumeration ;
-import java.util.Iterator ;
 import java.util.Map ;
 import java.util.concurrent.atomic.AtomicLong ;
 
@@ -31,7 +33,6 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse ;
 
 import org.apache.jena.fuseki.HttpNames ;
-import static org.apache.jena.fuseki.server.CounterName.* ;
 import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.fuseki.server.DatasetRegistry ;
 import org.apache.jena.fuseki.server.ServiceRef ;
@@ -330,10 +331,7 @@ public abstract class SPARQL_ServletBase
         // would only work for indirect. 
 
         String ds = null ;
-        Iterator<String> iter = DatasetRegistry.get().keys() ;
-        while(iter.hasNext())
-        {
-            String ds2 = iter.next();
+        for ( String ds2 : DatasetRegistry.get().keys() ) {
             if ( ! uri.startsWith(ds2) )
                 continue ;
 



Mime
View raw message