diff options
author | Simon Rettberg | 2023-09-27 18:31:32 +0200 |
---|---|---|
committer | Simon Rettberg | 2023-09-27 18:31:32 +0200 |
commit | 7de5c49c0da40932d30eff97601911b04895dfee (patch) | |
tree | a356138580b5f00494c5a0699891b1b71cda7cec | |
parent | Work around race condition instead of proper rearchitecturing (diff) | |
download | dnbd3-status-7de5c49c0da40932d30eff97601911b04895dfee.tar.gz dnbd3-status-7de5c49c0da40932d30eff97601911b04895dfee.tar.xz dnbd3-status-7de5c49c0da40932d30eff97601911b04895dfee.zip |
Remove legacy PNG output mode
-rw-r--r-- | pom.xml | 11 | ||||
-rw-r--r-- | src/main/java/org/openslx/dnbd3/status/StatisticsGenerator.java | 11 | ||||
-rw-r--r-- | src/main/java/org/openslx/dnbd3/status/WebServer.java | 16 | ||||
-rw-r--r-- | src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java | 6 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/ClientNode.java | 3 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/Edge.java | 18 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/Graph.java | 129 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/Node.java | 14 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/PngRenderer.java | 46 | ||||
-rw-r--r-- | src/main/java/org/openslx/graph/ServerNode.java | 3 |
10 files changed, 5 insertions, 252 deletions
@@ -52,23 +52,18 @@ <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> - <version>2.2.4</version> + <version>[2.2.4,2.9999]</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-math3</artifactId> - <version>3.5</version> - </dependency> - <dependency> - <groupId>ar.com.hjg</groupId> - <artifactId>pngj</artifactId> - <version>2.1.0</version> + <version>[3.5,3.99999]</version> </dependency> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> - <version>2.8</version> + <version>[2.8,2.9999]</version> </dependency> </dependencies> diff --git a/src/main/java/org/openslx/dnbd3/status/StatisticsGenerator.java b/src/main/java/org/openslx/dnbd3/status/StatisticsGenerator.java index 48b075d..3b70ab7 100644 --- a/src/main/java/org/openslx/dnbd3/status/StatisticsGenerator.java +++ b/src/main/java/org/openslx/dnbd3/status/StatisticsGenerator.java @@ -145,17 +145,6 @@ public class StatisticsGenerator } } - public byte[] getImagePng() - { - ensureUpToDate(); - synchronized ( graph ) { - if ( imgData == null ) { - imgData = graph.makeNextImage(); - } - } - return imgData; - } - public String getJson( boolean newFormat ) { ensureUpToDate(); diff --git a/src/main/java/org/openslx/dnbd3/status/WebServer.java b/src/main/java/org/openslx/dnbd3/status/WebServer.java index f652f6a..d67c22a 100644 --- a/src/main/java/org/openslx/dnbd3/status/WebServer.java +++ b/src/main/java/org/openslx/dnbd3/status/WebServer.java @@ -1,6 +1,5 @@ package org.openslx.dnbd3.status; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -45,8 +44,6 @@ public class WebServer extends NanoHTTPD String uri = session.getUri(); // Special/dynamic - if ( uri.equals( "/image.png" ) ) - return serveImage(); if ( uri.equals( "/data.json" ) ) return serveJson(false); if ( uri.equals( "/data2.json" ) ) @@ -87,19 +84,6 @@ public class WebServer extends NanoHTTPD return new NanoHTTPD.Response( NanoHTTPD.Response.Status.NOT_FOUND, "text/plain", "Nicht gefunden!" ); } - private NanoHTTPD.Response serveImage() - { - InputStream is = null; - byte[] imgData = imageGenerator.getImagePng(); - if ( imgData != null ) - is = new ByteArrayInputStream( imgData ); - if ( is == null ) { - return new NanoHTTPD.Response( NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain", "Internal Server Error" ); - } else { - return new NanoHTTPD.Response( NanoHTTPD.Response.Status.OK, "image/png", is ); - } - } - private NanoHTTPD.Response serveJson(boolean newFormat) { String data = imageGenerator.getJson(newFormat); diff --git a/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java b/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java index 492e371..a806912 100644 --- a/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java +++ b/src/main/java/org/openslx/dnbd3/status/poller/ServerPoller.java @@ -47,11 +47,11 @@ public class ServerPoller is = con.getInputStream(); } catch ( java.net.SocketTimeoutException e ) { - System.out.println( "Timeout " + this.server ); + //System.out.println( "Timeout " + this.server ); NanoHTTPD.safeClose( is ); return null; } catch ( java.io.IOException e ) { - System.out.println( "IOException " + this.server ); + //System.out.println( "IOException " + this.server ); NanoHTTPD.safeClose( is ); return null; } @@ -79,8 +79,6 @@ public class ServerPoller e.printStackTrace(); status = null; } - // TODO: http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html - // once dnbd3 server supports keep-alive connections return status; } diff --git a/src/main/java/org/openslx/graph/ClientNode.java b/src/main/java/org/openslx/graph/ClientNode.java index b1c826a..511a643 100644 --- a/src/main/java/org/openslx/graph/ClientNode.java +++ b/src/main/java/org/openslx/graph/ClientNode.java @@ -1,7 +1,5 @@ package org.openslx.graph; -import java.awt.Color; - public class ClientNode extends Node { @@ -11,7 +9,6 @@ public class ClientNode extends Node { super( ip, ip, null ); setDesiredDistance( 2 ); - setColor( Color.BLUE ); } @Override diff --git a/src/main/java/org/openslx/graph/Edge.java b/src/main/java/org/openslx/graph/Edge.java index c896651..86bfe13 100644 --- a/src/main/java/org/openslx/graph/Edge.java +++ b/src/main/java/org/openslx/graph/Edge.java @@ -1,7 +1,5 @@ package org.openslx.graph;
-import java.awt.Color;
-
import org.apache.commons.math3.util.FastMath;
public class Edge implements java.io.Serializable
@@ -12,20 +10,9 @@ public class Edge implements java.io.Serializable private double _weight;
private String _id = null;
private int _age = 0;
- private static final Color[] COLORS = new Color[ 20 ];
private final int _maxHealth;
private int _health;
- static
- {
- for ( int i = 0; i < COLORS.length; ++i ) {
- int r = blend( 255, 100, i, COLORS.length - 1 );
- int g = blend( 0, 100, i, COLORS.length - 1 );
- int b = blend( 0, 255, i, COLORS.length - 1 );
- COLORS[i] = new Color( r, g, b );
- }
- }
-
private static int blend( int a, int b, int current, int max )
{
a *= a;
@@ -121,9 +108,4 @@ public class Edge implements java.io.Serializable return _id;
}
- public Color getColor()
- {
- return COLORS[_age >= COLORS.length ? COLORS.length - 1 : _age];
- }
-
}
diff --git a/src/main/java/org/openslx/graph/Graph.java b/src/main/java/org/openslx/graph/Graph.java index 7f7ca64..4f2fc90 100644 --- a/src/main/java/org/openslx/graph/Graph.java +++ b/src/main/java/org/openslx/graph/Graph.java @@ -1,16 +1,7 @@ package org.openslx.graph;
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.Stroke;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -48,26 +39,12 @@ public class Graph implements java.io.Serializable private int _frameCount = 0;
- private static final Color COLOR_BG = new Color( 250, 250, 255 );
- private static final Color COLOR_TITLE = new Color( 200, 200, 255 );
- private static final Color COLOR_LABEL = new Color( 0, 0, 20 );
- private static final Color COLOR_LABEL_SHADOW = new Color( 220, 220, 220 );
- private static final Color COLOR_TITLE2 = new Color( 190, 190, 210 );
- private static final Color COLOR_EDGE = new Color( 100, 100, 255 );
-
private static final int IMG_X = 1280;
private static final int IMG_Y = 1024;
- private final Graphics2D graphicsContext;
- private final PngRenderer renderer;
-
public Graph( String label )
{
_label = label;
- BufferedImage targetImage = new BufferedImage( IMG_X, IMG_Y, BufferedImage.TYPE_INT_ARGB );
- graphicsContext = targetImage.createGraphics();
- graphicsContext.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
- renderer = new PngRenderer( targetImage );
}
// Add a Node to the Graph.
@@ -420,68 +397,6 @@ public class Graph implements java.io.Serializable }
- private static final Font FONT_64 = new Font( "SansSerif", Font.BOLD, 64 );
- private static final Font FONT_18 = new Font( "SansSerif", Font.BOLD, 18 );
- private static final Font FONT_12 = new Font( "SansSerif", Font.PLAIN, 12 );
- private static final Font FONT_10 = new Font( "SansSerif", Font.PLAIN, 10 );
- private static final Stroke STROKE_2 = new BasicStroke( 2.0f );
-
- public void drawImage( Set<Node> nodes, double edgeThreshold )
- {
-
- // Now actually draw the thing...
-
- graphicsContext.setColor( COLOR_BG );
- graphicsContext.fillRect( 0, 0, IMG_X, IMG_Y );
-
- graphicsContext.setColor( COLOR_TITLE );
- graphicsContext.setFont( FONT_64 );
- graphicsContext.drawString( _label, 20, 80 );
-
- graphicsContext.setColor( COLOR_TITLE2 );
- graphicsContext.setFont( FONT_18 );
- graphicsContext.drawString( _caption, 0, IMG_Y - 5 - 50 );
- graphicsContext.setFont( FONT_12 );
- graphicsContext.drawString( "This frame was drawn at " + new Date(), 0, IMG_Y - 5 );
-
- // Draw all edges...
- for ( Edge edge : _edges.values() ) {
- if ( edge.getWeight() < edgeThreshold ) {
- continue;
- }
-
- double weight = edge.getWeight();
-
- Node nodeA = edge.getSource();
- Node nodeB = edge.getTarget();
- int x1 = toImageX( nodeA );
- int y1 = toImageY( nodeA );
- int x2 = toImageX( nodeB );
- int y2 = toImageY( nodeB );
- graphicsContext.setStroke( new BasicStroke( (float) ( FastMath.log( weight + 1 ) * 0.1 ) + 1 ) );
- final int alpha = 102 + (int) ( 153 * weight / maxWeight );
- graphicsContext.setColor( new Color( ( edge.getColor().getRGB() & 0xffffff ) | ( alpha << 24 ), true ) );
- graphicsContext.drawLine( x1, y1, x2, y2 );
- }
-
- // Draw all nodes...
- graphicsContext.setStroke( STROKE_2 );
- graphicsContext.setFont( FONT_10 );
- for ( Node node : nodes ) {
- final int x = toImageX( node );
- final int y = toImageY( node );
- final int nodeRadius = node.getRadius();
- graphicsContext.setColor( node.getColor() );
- graphicsContext.fillOval( x - nodeRadius, y - nodeRadius, nodeRadius * 2, nodeRadius * 2 );
- graphicsContext.setColor( COLOR_EDGE );
- graphicsContext.drawOval( x - nodeRadius, y - nodeRadius, nodeRadius * 2, nodeRadius * 2 );
- graphicsContext.setColor( COLOR_LABEL_SHADOW );
- graphicsContext.drawString( node.toString(), x - ( node.toString().length() * 3 ) + 1, y - nodeRadius - 2 + 1 );
- graphicsContext.setColor( COLOR_LABEL );
- graphicsContext.drawString( node.toString(), x - ( node.toString().length() * 3 ), y - nodeRadius - 2 );
- }
- }
-
private int toImageX( Node node )
{
return (int) ( ( IMG_X - 50 ) * ( node.getX() - minX ) / ( maxX - minX ) ) + 25;
@@ -507,50 +422,6 @@ public class Graph implements java.io.Serializable _caption = caption;
}
- public byte[] makeNextImage()
- {
- _frameCount++;
-
- Set<Node> nodes = getConnectedNodes();
-
- doLayout( nodes, 200 );
- calcBounds( nodes );
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream( 100000 );
-
- try {
- drawImage( nodes, 0.1 );
- //ImageIO.write( targetImage, "png", baos );
- renderer.render( baos );
-
- writeGraph();
- return baos.toByteArray();
- } catch ( Exception e ) {
- System.out.println( "PieSpy has gone wibbly: " + e );
- e.printStackTrace();
- }
- return null;
- }
-
- // Serialize this Graph and write it to a File.
- public void writeGraph()
- {
- /*
- try {
- String strippedChannel = _label.toLowerCase().substring( 1 );
- File dir = new File( config.outputDirectory, strippedChannel );
- File file = new File( dir, strippedChannel + "-restore.dat" );
- ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream( file ) );
- oos.writeObject( SocialNetworkBot.VERSION );
- oos.writeObject( this );
- oos.flush();
- oos.close();
- } catch ( Exception e ) {
- // Do nothing?
- }
- */
- }
-
public Node getNode( String id )
{
return _nodes.get( new Node( id ) );
diff --git a/src/main/java/org/openslx/graph/Node.java b/src/main/java/org/openslx/graph/Node.java index d5e1dc2..e9f4280 100644 --- a/src/main/java/org/openslx/graph/Node.java +++ b/src/main/java/org/openslx/graph/Node.java @@ -1,7 +1,5 @@ package org.openslx.graph;
-import java.awt.Color;
-
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@@ -19,7 +17,6 @@ public class Node implements java.io.Serializable private double _fx;
private double _fy;
private int _health;
- private Color _color;
protected Node( String displayName )
{
@@ -40,7 +37,6 @@ public class Node implements java.io.Serializable _fx = 0;
_fy = 0;
_health = getMaxHealth();
- setColor( Color.BLUE );
}
public void swapPos( Node other )
@@ -137,16 +133,6 @@ public class Node implements java.io.Serializable _health--;
}
- public final Color getColor()
- {
- return _color;
- }
-
- protected final void setColor( Color color )
- {
- _color = color;
- }
-
public final int getRadius()
{
return 5;
diff --git a/src/main/java/org/openslx/graph/PngRenderer.java b/src/main/java/org/openslx/graph/PngRenderer.java deleted file mode 100644 index e51889c..0000000 --- a/src/main/java/org/openslx/graph/PngRenderer.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.openslx.graph; - -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; -import java.awt.image.SinglePixelPackedSampleModel; -import java.io.OutputStream; - -import ar.com.hjg.pngj.ImageInfo; -import ar.com.hjg.pngj.ImageLineByte; -import ar.com.hjg.pngj.PngWriter; - -public class PngRenderer -{ - private final ImageInfo imageInfo; - private final SinglePixelPackedSampleModel samplemodel; - private final int[] srcImageRawData; - private final ImageLineByte line; - private final byte[] lineBytes; - - public PngRenderer( BufferedImage image ) - { - imageInfo = new ImageInfo( image.getWidth(), image.getHeight(), 8, false ); - DataBufferInt db = ( (DataBufferInt)image.getRaster().getDataBuffer() ); - samplemodel = (SinglePixelPackedSampleModel)image.getSampleModel(); - line = new ImageLineByte( imageInfo ); - lineBytes = line.getScanline(); - srcImageRawData = db.getData(); - } - - public void render( OutputStream os ) - { - PngWriter pngWriter = new PngWriter( os, imageInfo ); - for ( int row = 0; row < imageInfo.rows; row++ ) { - int elem = samplemodel.getOffset( 0, row ); - for ( int col = 0, j = 0; col < imageInfo.cols; col++ ) { - int sample = srcImageRawData[elem++]; - lineBytes[j++] = (byte) ( ( sample & 0xFF0000 ) >> 16 ); // R - lineBytes[j++] = (byte) ( ( sample & 0xFF00 ) >> 8 ); // G - lineBytes[j++] = (byte) ( sample & 0xFF ); // B - } - pngWriter.writeRow( line, row ); - } - pngWriter.end(); - } - -} diff --git a/src/main/java/org/openslx/graph/ServerNode.java b/src/main/java/org/openslx/graph/ServerNode.java index d998a4c..63b9263 100644 --- a/src/main/java/org/openslx/graph/ServerNode.java +++ b/src/main/java/org/openslx/graph/ServerNode.java @@ -1,7 +1,5 @@ package org.openslx.graph; -import java.awt.Color; - public class ServerNode extends Node { private static final long serialVersionUID = 1642125227049150051L; @@ -10,7 +8,6 @@ public class ServerNode extends Node { super( ip, ip, null ); setDesiredDistance( 6 ); - setColor( Color.LIGHT_GRAY ); } @Override |