DPulse
Connection state visualizer.
DataPulse is a component for visualizing the status of different external services. It can be used to only check that a server is up and running or that a specific request returns the correct response.
The available visual modes right now are: Hexagon, LinkBox (a parallellogram) and Square. All visuals show the link status by color. Green for OK, Red for Down/Faulty and Yellow for status not known. Visuals also contain a color marker for visualizing time taken. Slow (orange), Medium (blue), Fast(green) and Not known (gray).
Component also has a small informational window for seeing fault information for clicked elements.
Polling is initiated by the client making an update request so right now connecting with multiple machines/browsers will pull up the amount of traffic the component generates.
Note. If the component is set to setVisible(false) the poller stops.
The DPulse component is quite versatile as connectors can be easily made for specific needs.
To make your own connectors all you need to do is extend the ConnectionVerifier interface and handle the population and upkeep of ConnectionInformation.
See HtmlConnector sample.
Note. the synchronizing of connectionInfo so it's not updated and read at the same time. Note. ConnectionInformation can be initialized with and int that sets the size of the Ping times that are saved.
The extended class can then be given to the DataPulse component.
Sample code
public class HtmlConnector implements ConnectionVerifier { private static final long serialVersionUID = 3192342994979899305L; private final int[] pingTimes = new int[] { 250, 750 }; private final ConnectionInformation connectionInfo; public HtmlConnector(final String url, final String description) { connectionInfo = new ConnectionInformation(); connectionInfo.setTarget(url); connectionInfo.setDescription(description); } public void testConnection() { httpResponse(); } private void httpResponse() { String exception = null; ConnectionState state = ConnectionState.NOT_KNOWN; Long time = null; HttpURLConnection urlConn = null; final long start = System.currentTimeMillis(); try { try { final URL url = new URL(connectionInfo.getTarget()); urlConn = (HttpURLConnection) url.openConnection(); urlConn.connect(); if (HttpURLConnection.HTTP_OK == urlConn.getResponseCode()) { state = ConnectionState.OK; } else { state = ConnectionState.DOWN; exception = "Server returned response code " + urlConn.getResponseCode(); } } finally { if (urlConn != null) { urlConn.disconnect(); } time = System.currentTimeMillis() - start; } } catch (final SocketTimeoutException ste) { exception = "Connection timed out. " + ste.getMessage(); time = System.currentTimeMillis() - start; state = ConnectionState.DOWN; } catch (final IOException e) { exception = "Error creating HTTP connection " + e.getMessage(); time = null; state = ConnectionState.DOWN; } synchronized (connectionInfo) { connectionInfo.setPingTime(time); connectionInfo.setState(state); connectionInfo.setException(exception); } } public PingState getPing() { Long pingTime; synchronized (connectionInfo) { pingTime = connectionInfo.getPingTime(); } if (connectionInfo.getState().equals(ConnectionState.DOWN)) { return PingState.NOT_KNOWN; } if (pingTime != null && pingTime < pingTimes[0]) { return PingState.FAST; } else if (pingTime != null && pingTime < pingTimes[1]) { return PingState.MEDIUM; } else if (pingTime != null) { return PingState.SLOW; } return PingState.NOT_KNOWN; } public ConnectionInformation getConnectionInfo() { synchronized (connectionInfo) { return connectionInfo; } } public ConnectionState getConnectionState() { return connectionInfo.getState(); } }
final DataPulse connectionTester = new DataPulse(); connectionTester.addConnection(new HtmlConnector("http://localhost/DPulse/random/", "Random result 1")); connectionTester.addConnection(new HtmlConnector("http://localhost/DPulse/random/", "Random result 2")); connectionTester.addConnection(new HtmlConnector("http://localhost/DPulse/random/", "Random result 3"));
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- Released
- 2012-08-13
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 6.8+
- Vaadin 7.0+ in 2.0.0
- Browser
- Internet Explorer
- Firefox
- Opera
- Safari
- Google Chrome
- Internet Explorer
Vaadin Add-on Directory
Find open-source widgets, add-ons, themes, and integrations for your Vaadin application.