Initial migrating to gradle, had to remove javafx files as the dependency was not working.
This commit is contained in:
parent
71344e931e
commit
defd9430cc
25 changed files with 311 additions and 1185 deletions
|
|
@ -38,9 +38,6 @@ import java.util.LinkedList;
|
|||
*/
|
||||
public class EuclideansAlgo {
|
||||
|
||||
/**
|
||||
* Simple Test
|
||||
*/
|
||||
public static void main(String[] args){
|
||||
MultiPrintStream.out.println("*** Correct Answer: ");
|
||||
MultiPrintStream.out.println("java.util.LinkedList{0, 2, 1, 1, 1, 4, 12, 102, 1, 1, 2, 3, 2, 2, 36}");
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class SQLQuery {
|
|||
//*******************************************
|
||||
// Main Types
|
||||
/**
|
||||
* <XMP>
|
||||
* <pre>
|
||||
* SELECT
|
||||
* [ALL | DISTINCT | DISTINCTROW ]
|
||||
* [FROM table_references
|
||||
|
|
@ -65,7 +65,7 @@ public class SQLQuery {
|
|||
* [ORDER BY {col_name | expr | position}
|
||||
* [ASC | DESC], ...]
|
||||
* [LIMIT {[offset,] row_count | row_count OFFSET offset}]
|
||||
* </XMP>
|
||||
* </pre>
|
||||
*/
|
||||
public static class SQLSelect extends SQLQueryItem{
|
||||
String[] params;
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ The MIT License (MIT)
|
||||
~
|
||||
~ Copyright (c) 2015 Ziver Koc
|
||||
~
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ The above copyright notice and this permission notice shall be included in
|
||||
~ all copies or substantial portions of the Software.
|
||||
~
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
~ THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
|
||||
prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="zutil.log.net.NetLogGuiClient">
|
||||
<MenuBar prefWidth="598.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<menus>
|
||||
<Menu mnemonicParsing="false" text="File">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Open File"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#handleConnectAction" text="Connect"/>
|
||||
<Menu mnemonicParsing="false" text="Previous">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Koc.se:8080"/>
|
||||
<MenuItem mnemonicParsing="false" text="localhost:8080"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<SeparatorMenuItem mnemonicParsing="false"/>
|
||||
<MenuItem mnemonicParsing="false" text="Export"/>
|
||||
<SeparatorMenuItem disable="true" mnemonicParsing="false"/>
|
||||
<MenuItem mnemonicParsing="false" onAction="#handleExitAction" text="Exit"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Edit">
|
||||
<items>
|
||||
<MenuItem disable="true" mnemonicParsing="false" text="Copy"/>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Help">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" onAction="#handleAboutAction" text="About"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
</MenuBar>
|
||||
<TabPane fx:id="tabPane" prefHeight="364.0" prefWidth="586.0" tabClosingPolicy="ALL_TABS"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="22.0"/>
|
||||
</AnchorPane>
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class NetLogClient extends Thread{
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private ConcurrentLinkedQueue<NetLogListener> listeners;
|
||||
private Socket s;
|
||||
|
||||
public NetLogClient(String host, int port) throws IOException{
|
||||
s = new Socket(host, port);
|
||||
listeners = new ConcurrentLinkedQueue<>();
|
||||
this.start();
|
||||
}
|
||||
|
||||
public void addListener(NetLogListener listener){
|
||||
logger.info("Registering new NetLogListener: "+listener.getClass().getName());
|
||||
listeners.add( listener );
|
||||
}
|
||||
|
||||
public void run(){
|
||||
try{
|
||||
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
||||
while( true ){
|
||||
Object o = in.readObject();
|
||||
|
||||
for( NetLogListener listener : listeners ){
|
||||
if( o instanceof NetLogMessage )
|
||||
listener.handleLogMessage((NetLogMessage)o);
|
||||
else if( o instanceof NetLogExceptionMessage )
|
||||
listener.handleExceptionMessage((NetLogExceptionMessage)o);
|
||||
else if( o instanceof NetLogStatusMessage )
|
||||
listener.handleStatusMessage((NetLogStatusMessage)o);
|
||||
else
|
||||
logger.warning("Received unknown message: "+o.getClass().getName());
|
||||
}
|
||||
}
|
||||
} catch( Exception e ){
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void close(){
|
||||
try{
|
||||
this.interrupt();
|
||||
s.close();
|
||||
} catch (Exception e){
|
||||
logger.log(Level.SEVERE, "Unable to close Client Socket.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/* LOG LEVELS */
|
||||
.SEVERE {
|
||||
-fx-control-inner-background: palevioletred;
|
||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||
}
|
||||
.WARNING {
|
||||
-fx-control-inner-background: yellow;
|
||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||
}
|
||||
.INFO { }
|
||||
.FINE {
|
||||
-fx-control-inner-background: lavender;
|
||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||
}
|
||||
.FINER {
|
||||
-fx-control-inner-background: lightblue ;
|
||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||
}
|
||||
.FINEST {
|
||||
-fx-control-inner-background: skyblue;
|
||||
-fx-accent: derive(-fx-control-inner-background, -40%);
|
||||
-fx-cell-hover-color: derive(-fx-control-inner-background, -20%);
|
||||
}
|
||||
|
||||
/* Clear empty rows */
|
||||
.table-row-cell:empty {
|
||||
-fx-background-color: null;
|
||||
}
|
||||
.table-row-cell:empty .table-cell {
|
||||
-fx-border-width: 0px;
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ The MIT License (MIT)
|
||||
~
|
||||
~ Copyright (c) 2015 Ziver Koc
|
||||
~
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ The above copyright notice and this permission notice shall be included in
|
||||
~ all copies or substantial portions of the Software.
|
||||
~
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
~ THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<?import javafx.collections.FXCollections?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.Group?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.net.URL?>
|
||||
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="zutil.log.net.NetLogGuiClientInstance">
|
||||
<stylesheets>
|
||||
<URL value="@NetLogClientInstance.css" />
|
||||
</stylesheets>
|
||||
<bottom>
|
||||
<ToolBar maxHeight="22.0" minHeight="19.0" prefHeight="22.0" prefWidth="839.0">
|
||||
<ProgressBar fx:id="progressBar" prefWidth="200.0" progress="0.0"/>
|
||||
<Label fx:id="errorLabel" textFill="RED">
|
||||
<font>
|
||||
<Font size="11.0"/>
|
||||
</font>
|
||||
</Label>
|
||||
<Region HBox.Hgrow="ALWAYS"/>
|
||||
<Separator orientation="VERTICAL" prefHeight="200.0"/>
|
||||
<Label fx:id="logCountLabel" text="0">
|
||||
<graphic>
|
||||
<Label text="Log Count:"/>
|
||||
</graphic>
|
||||
</Label>
|
||||
</ToolBar>
|
||||
</bottom>
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.7491525423728813" focusTraversable="true" orientation="VERTICAL" prefHeight="297.0"
|
||||
prefWidth="600.0">
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
|
||||
<children>
|
||||
<TableView fx:id="logTable" prefHeight="146.0" prefWidth="598.0" tableMenuButtonVisible="true"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0">
|
||||
<columns>
|
||||
<TableColumn editable="false" prefWidth="130.0" sortable="false" text="Timestamp"
|
||||
fx:id="logTimestampColumn"/>
|
||||
<TableColumn editable="false" prefWidth="75.0" sortable="false" text="Level"
|
||||
fx:id="logLevelColumn"/>
|
||||
<TableColumn editable="false" prefWidth="400.0" sortable="false" text="Log"
|
||||
fx:id="logColumn"/>
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
|
||||
<children>
|
||||
<TableView fx:id="exceptionTable" prefHeight="147.0" prefWidth="598.0" tableMenuButtonVisible="true"
|
||||
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
|
||||
AnchorPane.topAnchor="0.0">
|
||||
<columns>
|
||||
<TableColumn editable="false" prefWidth="45.0" style="-fx-alignment: TOP_CENTER;" text="#"
|
||||
fx:id="exCountColumn"/>
|
||||
<TableColumn editable="false" prefWidth="250.0"
|
||||
style="-fx-alignment: TOP_LEFT; -fx-font-weight: bold;" text="Exception"
|
||||
fx:id="exNameColumn"/>
|
||||
<TableColumn editable="false" prefWidth="300.0" style="-fx-alignment: TOP_LEFT;"
|
||||
text="Message" fx:id="exMessageColumn"/>
|
||||
<TableColumn editable="false" prefWidth="450.0" text="StackTrace" fx:id="exStackTraceColumn"/>
|
||||
</columns>
|
||||
</TableView>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</SplitPane>
|
||||
</center>
|
||||
<top>
|
||||
<ToolBar maxHeight="30.0" minHeight="22.0" prefHeight="30.0" prefWidth="839.0">
|
||||
<ToggleButton fx:id="pauseButton" mnemonicParsing="false" onAction="#handlePauseAction" text="Pause"/>
|
||||
<Region HBox.Hgrow="ALWAYS"/>
|
||||
<Group id="Group">
|
||||
<children>
|
||||
<Label fx:id="levelLabel" layoutY="-7.0" text="Log Level: "/>
|
||||
<ComboBox fx:id="levelComboBox" layoutX="60.0" layoutY="-9.0" onAction="#handleLevelChanged">
|
||||
<items>
|
||||
<FXCollections fx:factory="observableArrayList">
|
||||
<String fx:value="01 - ERROR"/>
|
||||
<String fx:value="02 - WARNING"/>
|
||||
<String fx:value="03 - INFO"/>
|
||||
<String fx:value="04 - FINE"/>
|
||||
<String fx:value="05 - FINER"/>
|
||||
<String fx:value="06 - FINEST"/>
|
||||
</FXCollections>
|
||||
</items>
|
||||
</ComboBox>
|
||||
</children>
|
||||
</Group>
|
||||
<Group id="Group">
|
||||
<children>
|
||||
<Label fx:id="intervalLabel" alignment="CENTER_RIGHT" layoutY="-7.0" prefWidth="60.0"
|
||||
text="Interval: "/>
|
||||
<ComboBox fx:id="intervalComboBox" layoutX="65.0" layoutY="-9.0" onAction="#handleIntervalChanged">
|
||||
<items>
|
||||
<FXCollections fx:factory="observableArrayList">
|
||||
<String fx:value="Instant"/>
|
||||
<String fx:value="3 sec"/>
|
||||
<String fx:value="5 sec"/>
|
||||
<String fx:value="10 sec"/>
|
||||
<String fx:value="30 sec"/>
|
||||
<String fx:value="60 sec"/>
|
||||
</FXCollections>
|
||||
</items>
|
||||
</ComboBox>
|
||||
</children>
|
||||
</Group>
|
||||
</ToolBar>
|
||||
</top>
|
||||
</BorderPane>
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import zutil.net.nio.message.Message;
|
||||
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class NetLogExceptionMessage implements Message {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int count;
|
||||
private String name;
|
||||
private String message;
|
||||
private String stackTrace;
|
||||
|
||||
NetLogExceptionMessage(String name, String message, String stackTrace){
|
||||
this.count = 1;
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
this.stackTrace = stackTrace;
|
||||
}
|
||||
|
||||
public NetLogExceptionMessage(LogRecord record) {
|
||||
Throwable exception = record.getThrown();
|
||||
|
||||
this.count = 1;
|
||||
this.name = exception.getClass().getName();
|
||||
this.message = exception.getMessage();
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
for(int i=0; i<exception.getStackTrace().length; i++){
|
||||
str.append(exception.getStackTrace()[i].toString());
|
||||
}
|
||||
this.stackTrace = str.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result
|
||||
+ ((stackTrace == null) ? 0 : stackTrace.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
NetLogExceptionMessage other = (NetLogExceptionMessage) obj;
|
||||
if (name.equals(other.name) && message.equals(other.message) &&
|
||||
stackTrace.equals(other.stackTrace)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addCount(int add){
|
||||
count += add;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getStackTrace() {
|
||||
return stackTrace;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NetLogGuiClient extends Application{
|
||||
public static final String VERSION = "0.1";
|
||||
|
||||
// UI elements
|
||||
@FXML
|
||||
private TabPane tabPane;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(NetLogGuiClient.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
Parent root = FXMLLoader.load(getClass().getResource("NetLogClient.fxml"));
|
||||
|
||||
stage.setTitle("NetLoggerClient ("+VERSION+")");
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
// Menu Actions
|
||||
@FXML
|
||||
protected void handleConnectAction(ActionEvent event) {
|
||||
try{
|
||||
tabPane.getTabs().add(new NetLoggerClientTab("koc.se", 8080));
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleExitAction(ActionEvent event) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleAboutAction(ActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
private class NetLoggerClientTab extends Tab{
|
||||
public NetLoggerClientTab(String host, int port) throws IOException{
|
||||
this.setText( host+":"+port );
|
||||
|
||||
Parent tabRoot = FXMLLoader.load(getClass().getResource("NetLogClientInstance.fxml"));
|
||||
this.setContent(tabRoot);
|
||||
AnchorPane.setRightAnchor(tabRoot, 0.0);
|
||||
//this.setOnClosed(new EventHandler<Event>() {
|
||||
// public void handle(Event e) {
|
||||
// handleDisconnectAction(e);
|
||||
// }
|
||||
//});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,222 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.util.Callback;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
private enum Status{RUNNING, PAUSED, DISCONNECTED}
|
||||
|
||||
// Logic variables
|
||||
private NetLogClient net;
|
||||
private Status status;
|
||||
|
||||
// UI elements
|
||||
@FXML private ToggleButton pauseButton;
|
||||
@FXML private Label levelLabel;
|
||||
@FXML private ComboBox levelComboBox;
|
||||
@FXML private Label intervalLabel;
|
||||
@FXML private ComboBox intervalComboBox;
|
||||
@FXML private ProgressBar progressBar;
|
||||
@FXML private Label errorLabel;
|
||||
@FXML private Label logCountLabel;
|
||||
|
||||
@FXML private TableView<NetLogMessage> logTable;
|
||||
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logColumn;
|
||||
|
||||
@FXML private TableView<NetLogExceptionMessage> exceptionTable;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
|
||||
|
||||
|
||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||
// Connect to Server
|
||||
try{
|
||||
net = new NetLogClient("127.0.0.1", 5050);
|
||||
net.addListener( this );
|
||||
status = Status.RUNNING;
|
||||
}catch(Exception e){
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
status = Status.DISCONNECTED;
|
||||
errorLabel.setText(e.getMessage());
|
||||
}
|
||||
updateStatus();
|
||||
|
||||
// Setup Gui
|
||||
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<>("timestamp"));
|
||||
logLevelColumn.setCellValueFactory(new PropertyValueFactory<>("level"));
|
||||
logLevelColumn.setCellFactory(new RowCssCellFactory<NetLogMessage,String>(){
|
||||
public String getStyleName(String item){
|
||||
return item;
|
||||
}
|
||||
});
|
||||
logColumn.setCellValueFactory(new PropertyValueFactory<>("log"));
|
||||
|
||||
exCountColumn.setCellValueFactory(new PropertyValueFactory<>("count"));
|
||||
exNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
|
||||
exMessageColumn.setCellValueFactory(new PropertyValueFactory<>("message"));
|
||||
exStackTraceColumn.setCellValueFactory(new PropertyValueFactory<>("stackTrace"));
|
||||
}
|
||||
|
||||
/************* NETWORK *****************/
|
||||
public void handleLogMessage(NetLogMessage msg) {
|
||||
if(status == Status.RUNNING){
|
||||
logTable.getItems().add(msg);
|
||||
|
||||
Platform.runLater(new Runnable() {
|
||||
public void run() {
|
||||
logCountLabel.setText("" + (Long.parseLong(logCountLabel.getText()) + 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void handleExceptionMessage(NetLogExceptionMessage msg) {
|
||||
if(status == Status.RUNNING){
|
||||
exceptionTable.getItems().remove(msg);
|
||||
exceptionTable.getItems().add(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleStatusMessage(NetLogStatusMessage msg) {
|
||||
if(status == Status.RUNNING){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*************** GUI *******************/
|
||||
@FXML
|
||||
protected void handlePauseAction(ActionEvent event) {
|
||||
if(status == Status.RUNNING){
|
||||
status = Status.PAUSED;
|
||||
logger.info("Logging paused");
|
||||
}
|
||||
else if(status == Status.PAUSED){
|
||||
status = Status.RUNNING;
|
||||
logger.info("Logging Unpaused");
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleDisconnectAction(Event event) {
|
||||
logger.info("Disconnecting from Log Server");
|
||||
net.close();
|
||||
status = Status.DISCONNECTED;
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleLevelChanged(ActionEvent event) {
|
||||
logger.info("Updating Log Level");
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleIntervalChanged(ActionEvent event) {
|
||||
logger.info("Updating Log Interval");
|
||||
}
|
||||
|
||||
private void updateStatus(){
|
||||
if(progressBar == null || pauseButton == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if(status == Status.RUNNING){
|
||||
progressBar.setProgress(-1.0);
|
||||
pauseButton.setText("Pause");
|
||||
}
|
||||
else if(status == Status.PAUSED){
|
||||
progressBar.setProgress(1.0);
|
||||
pauseButton.setText("Unpause");
|
||||
}
|
||||
else if(status == Status.DISCONNECTED){
|
||||
pauseButton.setDisable(true);
|
||||
levelLabel.setDisable(true);
|
||||
levelComboBox.setDisable(true);
|
||||
intervalLabel.setDisable(true);
|
||||
intervalComboBox.setDisable(true);
|
||||
|
||||
logTable.setDisable(true);
|
||||
exceptionTable.setDisable(true);
|
||||
|
||||
progressBar.setProgress(0);
|
||||
logCountLabel.setDisable(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* http://stackoverflow.com/questions/13697115/javafx-tableview-colors
|
||||
*/
|
||||
public abstract class RowCssCellFactory<S,T> implements Callback<TableColumn<S,T>, TableCell<S,T>> {
|
||||
|
||||
public TableCell<S,T> call(TableColumn<S,T> p) {
|
||||
TableCell<S, T> cell = new TableCell<S, T>() {
|
||||
@Override
|
||||
public void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty ? null : getString());
|
||||
setGraphic(null);
|
||||
|
||||
String style = getStyleName(item);
|
||||
if(style != null){
|
||||
TableRow<?> row = getTableRow();
|
||||
row.getStyleClass().add(style);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSelected(boolean upd){
|
||||
super.updateSelected(upd);
|
||||
}
|
||||
|
||||
|
||||
private String getString() {
|
||||
return getItem() == null ? "NULL" : getItem().toString();
|
||||
}
|
||||
};
|
||||
return cell;
|
||||
}
|
||||
|
||||
public abstract String getStyleName(T item);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
|
||||
public interface NetLogListener {
|
||||
/**
|
||||
* Handle incoming log messages
|
||||
*/
|
||||
void handleLogMessage(NetLogMessage log);
|
||||
|
||||
/**
|
||||
* Handle incoming exception messages
|
||||
*/
|
||||
void handleExceptionMessage(NetLogExceptionMessage exception);
|
||||
|
||||
/**
|
||||
* Handle incoming status messages
|
||||
*/
|
||||
void handleStatusMessage(NetLogStatusMessage status);
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import zutil.net.nio.message.Message;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class NetLogMessage implements Message {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final SimpleDateFormat dataFormat =
|
||||
new SimpleDateFormat("yyyy--MM-dd HH:mm:ss");
|
||||
|
||||
private long timestamp;
|
||||
private String level;
|
||||
private int threadID;
|
||||
private String className;
|
||||
private String methodName;
|
||||
private String log;
|
||||
|
||||
|
||||
public NetLogMessage(String level, long timestamp, String log){
|
||||
this.level = level;
|
||||
this.timestamp = timestamp;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public NetLogMessage( LogRecord record ){
|
||||
timestamp = record.getMillis();
|
||||
level = record.getLevel().getName();
|
||||
threadID = record.getThreadID();
|
||||
className = record.getSourceClassName();
|
||||
methodName = record.getSourceMethodName();
|
||||
log = record.getMessage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getTimestamp() {
|
||||
return dataFormat.format(new Date(timestamp));
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int getThreadID() {
|
||||
return threadID;
|
||||
}
|
||||
|
||||
public void setThreadID(int threadID) {
|
||||
this.threadID = threadID;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public void setMethodName(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public void setLog(String log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.nio.message.Message;
|
||||
import zutil.net.threaded.ThreadedTCPNetworkServer;
|
||||
import zutil.net.threaded.ThreadedTCPNetworkServerThread;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public class NetLogServer extends Handler {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
private NetLogNetwork net;
|
||||
private ConcurrentHashMap<NetLogExceptionMessage,NetLogExceptionMessage> exceptions;
|
||||
|
||||
/**
|
||||
* @param port the port the server will listen on
|
||||
*/
|
||||
public NetLogServer(int port) {
|
||||
super();
|
||||
exceptions = new ConcurrentHashMap<>();
|
||||
net = new NetLogNetwork(port);
|
||||
net.start();
|
||||
}
|
||||
|
||||
|
||||
public void publish(LogRecord record) {
|
||||
// ensure that this log record should be logged by this Handler
|
||||
if (!isLoggable(record))
|
||||
return;
|
||||
|
||||
// Output the formatted data to the file
|
||||
if(record.getThrown() != null){
|
||||
NetLogExceptionMessage exception = new NetLogExceptionMessage(record);
|
||||
if(!exceptions.containsKey(exception)){
|
||||
logger.finest("Received new exception: "+exception);
|
||||
exceptions.put(exception, exception);
|
||||
net.sendMessage( exception );
|
||||
}
|
||||
else{
|
||||
exception = exceptions.get(exception);
|
||||
exception.addCount(1);
|
||||
logger.finest("Received known exception(Count: "+exception.getCount()+"): "+exception);
|
||||
net.sendMessage( exception );
|
||||
}
|
||||
}
|
||||
else{
|
||||
NetLogMessage log = new NetLogMessage(record);
|
||||
net.sendMessage( log );
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {}
|
||||
|
||||
public void close() {
|
||||
net.close();
|
||||
}
|
||||
|
||||
|
||||
class NetLogNetwork extends ThreadedTCPNetworkServer{
|
||||
private ConcurrentLinkedQueue<NetLogServerThread> threads;
|
||||
|
||||
public NetLogNetwork(int port) {
|
||||
super(port);
|
||||
threads = new ConcurrentLinkedQueue<>();
|
||||
}
|
||||
|
||||
public void sendMessage(Message log){
|
||||
for( NetLogServerThread thread : threads ){
|
||||
thread.sendMessage( log );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
|
||||
try {
|
||||
return new NetLogServerThread(s);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Unable to start Client thread", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
class NetLogServerThread implements ThreadedTCPNetworkServerThread{
|
||||
private ObjectOutputStream out;
|
||||
private ObjectInputStream in;
|
||||
private Socket s;
|
||||
|
||||
public NetLogServerThread(Socket s) throws IOException{
|
||||
this.s = s;
|
||||
logger.info("Client connected: "+s.getInetAddress());
|
||||
out = new ObjectOutputStream( s.getOutputStream() );
|
||||
in = new ObjectInputStream( s.getInputStream() );
|
||||
|
||||
sendAllExceptions();
|
||||
threads.add( this );
|
||||
}
|
||||
|
||||
public void sendMessage(Message msg){
|
||||
try {
|
||||
out.writeObject( msg );
|
||||
out.reset();
|
||||
} catch (Exception e) {
|
||||
this.close();
|
||||
logger.log(Level.SEVERE, "Unable to send message to client: "+s.getInetAddress(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAllExceptions(){
|
||||
logger.fine("Sending all exceptions to client: "+s.getInetAddress());
|
||||
for(NetLogExceptionMessage e : exceptions.values())
|
||||
sendMessage(e);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while( true ){
|
||||
in.readObject();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
} finally {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void close(){
|
||||
try {
|
||||
threads.remove(this);
|
||||
logger.info("Client disconnected: "+s.getInetAddress());
|
||||
out.close();
|
||||
s.close();
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.SEVERE, "Unable to close Client Socket", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Ziver Koc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package zutil.log.net;
|
||||
|
||||
import zutil.net.nio.message.Message;
|
||||
|
||||
public class NetLogStatusMessage implements Message{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public long totalMemory;
|
||||
public long freememory;
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ public class LinearRegression {
|
|||
|
||||
/**
|
||||
* Linear Regression cost method.
|
||||
* <br /><br />
|
||||
* <p><br>
|
||||
* <i>
|
||||
* J(O) = 1 / (2 * m) * Σ { ( h(Xi) - Yi )^2 }
|
||||
* </i><br>
|
||||
|
|
@ -65,11 +65,11 @@ public class LinearRegression {
|
|||
|
||||
/**
|
||||
* Gradient Descent algorithm
|
||||
* <br /><br />
|
||||
* <p><br>
|
||||
* <i>
|
||||
* Oj = Oj - α * (1 / m) * Σ { ( h(Xi) - Yi ) * Xij }
|
||||
* </i><br />
|
||||
*
|
||||
* </i>
|
||||
* <br>
|
||||
* @return the theta that was found to minimize the cost function
|
||||
*/
|
||||
public static double[] gradientDescentIteration(double[][] x, double[] y, double[] theta, double alpha){
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package zutil.ml.neural;
|
|||
|
||||
/**
|
||||
* This class represents one "nuron" in a neural network.
|
||||
*
|
||||
* <p/><b>From Wikipedia: </b>
|
||||
* <blockquote cite="https://en.wikipedia.org/wiki/Perceptron">
|
||||
* <p>
|
||||
* <b>From Wikipedia:</b> https://en.wikipedia.org/wiki/Perceptron
|
||||
* <blockquote>
|
||||
* The perceptron is an algorithm for supervised learning of
|
||||
* binary classifiers (functions that can decide whether an
|
||||
* input, represented by a vector of numbers, belongs to some
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class MqttPacketConnect extends MqttPacketHeader {
|
|||
private int protocolNameLength = 4;
|
||||
/**
|
||||
* The Protocol Name is a UTF-8 encoded string that represents
|
||||
* the protocol name “MQTT”, capitalized as shown. The string,
|
||||
* the protocol name "MQTT", capitalized as shown. The string,
|
||||
* its offset and length will not be changed by future versions
|
||||
* of the MQTT specification.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class BBCodeParser {
|
|||
* Registers a new BBCode to the parser. Only one type of BBCode allowed.
|
||||
*
|
||||
* @param bbcode is the BBCode e.g. "b" or "url"
|
||||
* @param html is the corresponding HTML e.g. "<a href='%1'>%2</a>"
|
||||
* @param html is the corresponding HTML e.g. {@code <a href='%1'>%2</a>}
|
||||
* where the %x corresponds to BBCode like this: [url=%1]%2[/url]
|
||||
*/
|
||||
public void addBBCode(String bbcode, String html){
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import java.util.logging.Logger;
|
|||
* Class for generating dynamic text/code from set data.
|
||||
* The syntax is similar to the javascript mustache library.
|
||||
*
|
||||
* <br /><br />
|
||||
* <p><br>
|
||||
* Supported tags:
|
||||
* <ul>
|
||||
* <li><b> {{key}} </b><br>
|
||||
|
|
|
|||
|
|
@ -47,15 +47,15 @@ import java.util.logging.Logger;
|
|||
* object the {@link Configurator#setValues(DataNode)} or {@link Configurator#setValues(Map)}
|
||||
* can be used to set the individual fields and finally call {@link Configurator#applyConfiguration()}
|
||||
* to configure the target object.
|
||||
* <br />
|
||||
* <p>
|
||||
* External listener can be registered to be called before or after configuration changes
|
||||
* by implementing {@link PreConfigurationActionListener} or {@link PostConfigurationActionListener}.
|
||||
* The configured object will autmatically be registered as a listener if it also implements
|
||||
* these interfaces.
|
||||
*
|
||||
* <br>
|
||||
* <p>
|
||||
* Supported field types: String, int, boolean, enum
|
||||
* <br>
|
||||
* <p>
|
||||
* Created by Ziver
|
||||
*/
|
||||
public class Configurator<T> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue