List of usage examples for java.util LinkedList removeLast
public E removeLast()
From source file:com.mirth.connect.plugins.dashboardstatus.DashboardConnectorStatusMonitor.java
public void updateStatus(String connectorId, ConnectorType type, Event event, Socket socket) { String stateImage = COLOR_BLACK; String stateText = STATE_UNKNOWN; boolean updateStatus = true; switch (event) { case INITIALIZED: switch (type) { case LISTENER: stateImage = COLOR_YELLOW;//from www. j a va2 s. com stateText = STATE_WAITING; break; case READER: stateImage = COLOR_YELLOW; stateText = STATE_IDLE; break; } break; case CONNECTED: switch (type) { case LISTENER: if (socket != null) { addConnectionToSocketSet(socket, connectorId); stateImage = COLOR_GREEN; stateText = STATE_CONNECTED + " (" + getSocketSetCount(connectorId) + ")"; } else { stateImage = COLOR_GREEN; stateText = STATE_CONNECTED; } break; case READER: stateImage = COLOR_GREEN; stateText = STATE_POLLING; break; } break; case DISCONNECTED: switch (type) { case LISTENER: if (socket != null) { removeConnectionInSocketSet(socket, connectorId); int connectedSockets = getSocketSetCount(connectorId); if (connectedSockets == 0) { stateImage = COLOR_YELLOW; stateText = STATE_WAITING; } else { stateImage = COLOR_GREEN; stateText = STATE_CONNECTED + " (" + connectedSockets + ")"; } } else { clearSocketSet(connectorId); stateImage = COLOR_RED; stateText = STATE_DISCONNECTED; } break; case READER: stateImage = COLOR_RED; stateText = STATE_NOT_POLLING; break; case WRITER: stateImage = COLOR_RED; stateText = STATE_DISCONNECTED; break; case SENDER: stateImage = COLOR_RED; stateText = STATE_DISCONNECTED; break; } break; case BUSY: switch (type) { case READER: stateImage = COLOR_GREEN; stateText = STATE_READING; break; case LISTENER: stateImage = COLOR_GREEN; stateText = STATE_RECEIVING; break; case WRITER: stateImage = COLOR_YELLOW; stateText = STATE_WRITING; break; case SENDER: stateImage = COLOR_YELLOW; stateText = STATE_SENDING; break; } break; case DONE: switch (type) { case READER: stateImage = COLOR_YELLOW; stateText = STATE_IDLE; break; case LISTENER: if (socket != null) { stateImage = COLOR_GREEN; stateText = STATE_CONNECTED + " (" + getSocketSetCount(connectorId) + ")"; } else { stateImage = COLOR_YELLOW; stateText = STATE_WAITING; } break; } break; case ATTEMPTING: switch (type) { case WRITER: stateImage = COLOR_YELLOW; stateText = STATE_ATTEMPTING; break; case SENDER: stateImage = COLOR_YELLOW; stateText = STATE_ATTEMPTING; break; } break; default: updateStatus = false; break; } if (updateStatus) { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); String channelName = ""; // this will be overwritten down below. If not, something's wrong. String connectorType = type.toString(); String information = ""; /* * check 'connectorId' - contains destination_1_connector, etc. * connectorId consists of id_source_connector for sources, and * id_destination_x_connector for destinations. i.e. tokenCount will * be 3 for sources and 4 for destinations. Note that READER and * LISTENER are sources, and WRITER and SENDER are destinations. */ StringTokenizer tokenizer = new StringTokenizer(connectorId, "_"); String channelId = tokenizer.nextToken(); int destinationIndex; LinkedList<String[]> channelLog = null; Channel channel = ControllerFactory.getFactory().createChannelController() .getDeployedChannelById(channelId); if (channel != null) { channelName = channel.getName(); // grab the channel's log from the HashMap, if not exist, create // one. if (connectorInfoLogs.containsKey(channelName)) { channelLog = connectorInfoLogs.get(channelName); } else { channelLog = new LinkedList<String[]>(); } Connector connector = null; switch (type) { case READER: connectorType = "Source: " + channel.getSourceConnector().getTransportName() + " (" + channel.getSourceConnector().getTransformer().getInboundProtocol().toString() + " -> " + channel.getSourceConnector().getTransformer().getOutboundProtocol().toString() + ")"; break; case LISTENER: connectorType = "Source: " + channel.getSourceConnector().getTransportName() + " (" + channel.getSourceConnector().getTransformer().getInboundProtocol().toString() + " -> " + channel.getSourceConnector().getTransformer().getOutboundProtocol().toString() + ")"; break; case WRITER: tokenizer.nextToken(); // destinationId begins from 1, so subtract by 1 for the // arrayIndex. destinationIndex = Integer.valueOf(tokenizer.nextToken()) - 1; connector = channel.getDestinationConnectors().get(destinationIndex); connectorType = "Destination: " + connector.getTransportName() + " - " + connector.getName(); if (connector.getTransportName().equals(FileWriterProperties.name)) { // Destination - File Writer. switch (event) { case BUSY: information = FileWriterProperties.getInformation(connector.getProperties()); break; } } else if (connector.getTransportName().equals(DatabaseWriterProperties.name)) { // Destination - Database Writer. information = DatabaseWriterProperties.getInformation(connector.getProperties()); } else if (connector.getTransportName().equals(JMSWriterProperties.name)) { // Destination - JMS Writer. information = JMSWriterProperties.getInformation(connector.getProperties()); } else if (connector.getTransportName().equals(DocumentWriterProperties.name)) { // Destination - Document Writer. information = DocumentWriterProperties.getInformation(connector.getProperties()); } break; case SENDER: tokenizer.nextToken(); // destinationId begins from 1, so subtract by 1 for the // arrayIndex. destinationIndex = Integer.valueOf(tokenizer.nextToken()) - 1; connector = channel.getDestinationConnectors().get(destinationIndex); connectorType = "Destination: " + connector.getTransportName() + " - " + connector.getName(); if (connector.getTransportName().equals(HttpSenderProperties.name)) { // Destination - HTTP Sender. information = HttpSenderProperties.getInformation(connector.getProperties()); } else if (connector.getTransportName().equals(ChannelWriterProperties.name)) { // Destination - Channel Writer. Channel targetChannel = ControllerFactory.getFactory().createChannelController() .getDeployedChannelById( ChannelWriterProperties.getInformation(connector.getProperties())); if (targetChannel == null) { information = "Target Channel: None"; } else { information = "Target Channel: " + targetChannel.getName(); } } else if (connector.getTransportName().equals(SmtpSenderProperties.name)) { // Destination - SMTP Sender. information = SmtpSenderProperties.getInformation(connector.getProperties()); } else if (connector.getTransportName().equals(TCPSenderProperties.name)) { // Destination - TCP Sender. // The useful info for TCP Sender - host:port will // be taken care of by the socket below. } else if (connector.getTransportName().equals(LLPSenderProperties.name)) { // Destination - LLP Sender. // The useful info for LLP Sender - host:port will // be taken care of by the socket below. } else if (connector.getTransportName().equals(WebServiceSenderProperties.name)) { // Destination - Web Service Sender. // information = ""; } break; } } if (socket != null) { String sendingAddress = socket.getLocalAddress().toString() + ":" + socket.getLocalPort(); String receivingAddress = socket.getInetAddress().toString() + ":" + socket.getPort(); // If addresses begin with a slash "/", remove it. if (sendingAddress.startsWith("/")) { sendingAddress = sendingAddress.substring(1); } if (receivingAddress.startsWith("/")) { receivingAddress = receivingAddress.substring(1); } information += "Sender: " + sendingAddress + " Receiver: " + receivingAddress; } if (channelLog != null) { synchronized (this) { if (channelLog.size() == MAX_LOG_SIZE) { channelLog.removeLast(); } channelLog.addFirst(new String[] { String.valueOf(logId), channelName, dateFormat.format(timestamp), connectorType, event.toString(), information }); if (entireConnectorInfoLogs.size() == MAX_LOG_SIZE) { entireConnectorInfoLogs.removeLast(); } entireConnectorInfoLogs.addFirst(new String[] { String.valueOf(logId), channelName, dateFormat.format(timestamp), connectorType, event.toString(), information }); logId++; // put the channel log into the HashMap. connectorInfoLogs.put(channelName, channelLog); } } connectorStateMap.put(connectorId, new String[] { stateImage, stateText }); } }