db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From be...@apache.org
Subject svn commit: r631997 - in /db/derby/code/trunk/java/drda/org/apache/derby: impl/drda/ mbeans/drda/
Date Thu, 28 Feb 2008 15:20:57 GMT
Author: bernt
Date: Thu Feb 28 07:20:49 2008
New Revision: 631997

URL: http://svn.apache.org/viewvc?rev=631997&view=rev
Log:
DERBY-3435 Added some live data to the network server MBean

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerMBeanImpl.java
    db/derby/code/trunk/java/drda/org/apache/derby/mbeans/drda/NetworkServerMBean.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java Thu Feb 28 07:20:49
2008
@@ -156,6 +156,12 @@
     
     // State whether doing layer B Streaming or not.
     private boolean doingLayerBStreaming = false;;
+    
+    // For JMX statistics. Volatile to ensure we 
+    // get one complete long, but we don't bother to synchronize, 
+    // since this is just statistics.
+    
+    volatile long totalByteCount = 0;
 
 	// constructor
 	DDMReader (DRDAConnThread agent, DssTrace dssTrace)
@@ -1931,6 +1937,7 @@
 				  "InputStream.read()", "insufficient data", "*");
 			}
 		}
+        totalByteCount += totalBytesRead;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java Thu Feb 28 07:20:49
2008
@@ -111,6 +111,12 @@
 	/** Encoder which encodes strings with the server's default encoding. */
 	private final CharsetEncoder encoder;
 
+    // For JMX statistics. Volatile to ensure we 
+    // get one complete long, but we don't bother to synchronize, 
+    // since this is just statistics.
+    
+    volatile long totalByteCount = 0;
+    
 	DDMWriter (CcsidManager ccsidManager, DRDAConnThread agent, DssTrace dssTrace)
 	{
 		this.buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
@@ -1214,6 +1220,7 @@
 			}
 			reset(dssTrace);
 		}
+        totalByteCount += length;
 	}
 
 	// private methods

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu Feb 28
07:20:49 2008
@@ -8232,11 +8232,22 @@
 			writeSQLCARDs(reportWarning, updateCount);
 	}
 
+    boolean hasSession() {
+        return session != null;
+    }
+    
+    long getBytesRead() {
+        return reader.totalByteCount;
+    }
+    
+    long getBytesWritten() {
+        return writer.totalByteCount;
+    }
 
 	protected String buildRuntimeInfo(String indent, LocalizedResource localLangUtil )
 	{
 		String s ="";
-		if (session == null)
+		if (!hasSession())
 			return s;
 		else
 			s += session.buildRuntimeInfo("", localLangUtil);

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Thu Feb 28 07:20:49 2008
@@ -3844,7 +3844,44 @@
 		
 		return s;
 	}
+    
+    long getBytesRead() {
+        long count=0;
+        for (int i = 0; i < threadList.size(); i++) {
+            count += ((DRDAConnThread)threadList.get(i)).getBytesRead();
+        }
+        return count;
+    }
+    
+     long getBytesWritten() {
+        long count=0;
+        for (int i = 0; i < threadList.size(); i++) {
+            count += ((DRDAConnThread)threadList.get(i)).getBytesWritten();
+        }
+        return count;
+    }
+     
+    int getActiveSessions() {
+        int count=0;
+        for (int i = 0; i < threadList.size(); i++) {
+           if (((DRDAConnThread)threadList.get(i)).hasSession()) {
+               count++;
+           }
+        }
+        return count;
+    }
 
+    int getRunQueueSize() {
+        return runQueue.size();
+    }
+    
+    int getThreadListSize() {
+        return threadList.size();
+    }
+    
+    int getConnectionNumber() {
+        return connNum;
+    }
 
 	protected void setClientLocale(String locale)
 	{

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerMBeanImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerMBeanImpl.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerMBeanImpl.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerMBeanImpl.java Thu
Feb 28 07:20:49 2008
@@ -205,9 +205,60 @@
     }
      **/
     
+    public int getActiveSessions() {
+        return server.getActiveSessions();
+    }
     
+    public int getWaitingSessions() {
+        return server.getRunQueueSize();
+    }
     
+    public int getConnectionThreads() {
+        return server.getThreadListSize();
+    }
      
+    public int getNumberOfConnections() {
+        return server.getConnectionNumber();
+    }
+    
+    public long getBytesReceived() {
+        return server.getBytesRead();
+    }
+    
+    public long getBytesSent() {
+        return server.getBytesWritten();
+    }
+    
+    private long lastReceiveTime = System.currentTimeMillis();
+    private long lastReceiveBytes = 0;
+    private int receiveResult = 0;
+    
+    public int getBytesReceivedPerSecond(){
+        long now = System.currentTimeMillis();
+        if (now - lastReceiveTime >= 1000) {
+            long count = getBytesReceived();
+            receiveResult = (int)((count - lastReceiveBytes)/((now - lastReceiveTime)/1000));
+            lastReceiveTime = now;
+            lastReceiveBytes = count;
+        }
+        return receiveResult;
+    }
+
+    private long lastSentTime = System.currentTimeMillis();
+    private long lastSentBytes = 0;
+    private int sentResult = 0;
+
+    public int getBytesSentPerSecond(){
+        long now = System.currentTimeMillis();
+        if (now - lastSentTime >= 1000) {
+            long count = getBytesSent();
+            sentResult = (int)((count - lastSentBytes)/((now - lastSentTime)/1000));
+            lastSentTime = now;
+            lastSentBytes = count;
+        }
+        return sentResult;
+    }
+
     // ------------------------- MBEAN OPERATIONS  ----------------------------
     
     /**

Modified: db/derby/code/trunk/java/drda/org/apache/derby/mbeans/drda/NetworkServerMBean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/mbeans/drda/NetworkServerMBean.java?rev=631997&r1=631996&r2=631997&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/mbeans/drda/NetworkServerMBean.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/mbeans/drda/NetworkServerMBean.java Thu
Feb 28 07:20:49 2008
@@ -137,6 +137,59 @@
     public String getDrdaTraceDirectory();
     //public void setDrdaTraceDirectory(String dir) throws Exception;
 
+    /**
+     * Get the number of active sessions
+     * @return number of active sessions
+     */
+    public int getActiveSessions();
+    
+    /**
+     * get the number of waiting sessions. Always 0 if drdaMaxThreads is 0.
+     * @return number of waiting sessions
+     */
+    public int getWaitingSessions();
+    
+    /**
+     * Get the size of the thread pool.
+     * @return size of thread pool
+     */
+    public int getConnectionThreads();
+    
+    /**
+     * Get the accumulated number of connections.
+     * @return number of connections.
+     */
+    public int getNumberOfConnections();
+    
+    /**
+     * Get the total number of bytes read
+     * @return number of bytes
+     */
+    public long getBytesReceived();
+    
+    /** 
+     * Get the total number of bytes written.
+     * @return number of bytes
+     */
+    public long getBytesSent();
+    
+    /**
+     * Get the number of bytes received pr second. 
+     * Shortest interval measured is 1 second.
+     * @return bytes per millisecond
+     */
+    
+    public int getBytesReceivedPerSecond();
+    
+     /**
+     * Get the number of bytes sent pr second. 
+     * Shortest interval measured is 1 second.
+     * @return bytes per millisecond
+     */
+    
+    public int getBytesSentPerSecond();
+    
+    
     
     // ---
     // ----------------- MBean operations ------------------------------------



Mime
View raw message