v0.4 stabilization

master
Dmitry Isaenko 2019-01-25 06:44:06 +03:00
parent c8ab5a0964
commit 9de9f8d36f
11 changed files with 371 additions and 145 deletions

View File

@ -23,6 +23,7 @@ Source code spreads under the GNU General Public License v3 or higher. Please se
Used libraries: Used libraries:
* GSON: https://github.com/google/gson * GSON: https://github.com/google/gson
* sqliteJDBC: https://bitbucket.org/xerial/sqlite-jdbc * sqliteJDBC: https://bitbucket.org/xerial/sqlite-jdbc
* mongodb-driver-sync: https://mongodb.github.io/mongo-java-driver/3.9/
## TODO: ## TODO:

View File

@ -22,18 +22,17 @@ public class BotDriver {
} }
public static synchronized Worker getWorker(String serverName, String chanelName){ public static synchronized Worker getWorker(String serverName, String chanelName){
if (serverDriver.containsKey(serverName)) { if (serverDriver.containsKey(serverName)) {
switch (serverDriver.get(serverName)[0][0]) { switch (serverDriver.get(serverName)[0][0].toLowerCase()) {
case "Files": case "files":
return new BotFilesWorker(serverName, serverDriver.get(serverName)[1], chanelName); BotFilesWorker botFilesWorker = new BotFilesWorker(serverName, serverDriver.get(serverName)[1], chanelName);
case "SQLite": return validateConstancy(botFilesWorker, serverName, chanelName);
return new BotSQLiteWorker(serverName, serverDriver.get(serverName)[1], chanelName); case "sqlite":
case "MongoDB": BotSQLiteWorker botSQLiteWorker = new BotSQLiteWorker(serverName, serverDriver.get(serverName)[1], chanelName);
return validateConstancy(botSQLiteWorker, serverName, chanelName);
case "mongodb":
BotMongoWorker botMongoWorker = new BotMongoWorker(serverName, serverDriver.get(serverName)[1], chanelName); BotMongoWorker botMongoWorker = new BotMongoWorker(serverName, serverDriver.get(serverName)[1], chanelName);
if (botMongoWorker.isConsistent()) return validateConstancy(botMongoWorker, serverName, chanelName);
return botMongoWorker; case "zero":
else
System.out.println("BotDriver: Unable to use MongoWorker for "+serverName+". Using ZeroWorker instead."); // else, fall down and use BotZeroWorker.
case "Zero":
return new BotZeroWorker(); return new BotZeroWorker();
default: default:
System.out.println("Configuration issue: BotDriver->getWorker() can't find required driver \"" System.out.println("Configuration issue: BotDriver->getWorker() can't find required driver \""
@ -44,4 +43,13 @@ public class BotDriver {
} }
return null; return null;
} }
private static Worker validateConstancy(Worker worker, String srv, String chan){ // synchronized?
if (worker.isConsistent()){
return worker;
}
else {
System.out.println("BotDriver: Unable to use "+worker.getClass().getSimpleName()+" for "+srv+"/"+chan+". Using ZeroWorker instead.");
return new BotZeroWorker();
}
}
} }

View File

@ -16,31 +16,35 @@ public class BotFilesWorker implements Worker {
private LocalDate fileWriterDay; private LocalDate fileWriterDay;
private FileWriter fileWriter; private FileWriter fileWriter;
public BotFilesWorker(String server, String[] driverParameters, String channel){ private String ircServer; // hold for debug only
if (System.getProperty("os.name").startsWith("Windows")){
channel = channel.replaceAll("\",",",");
}
else {
channel = channel.replaceAll("/",",");
}
driverParameters[0] = driverParameters[0].trim(); //Consider parameters[0] as dirLocation public BotFilesWorker(String server, String[] driverParameters, String channel){
String dirLocation; ircServer = server;
if (driverParameters[0].endsWith(File.separator)) dateFormat = DateTimeFormatter.ofPattern("HH:mm:ss");
dirLocation = driverParameters[0]+server;
channel = channel.replaceAll(File.separator, ",");
String dirLocation = driverParameters[0].trim();
if (dirLocation.endsWith(File.separator))
dirLocation = dirLocation+server;
else else
dirLocation = driverParameters[0]+File.separator+server; dirLocation = dirLocation+File.separator+server;
File dir = new File(dirLocation);
dir.mkdirs();
if (!dir.exists()) {
System.out.println("Unable to create directory to store files: " + dirLocation); //TODO: notify requester
this.consistent = false;
}
this.filePath = dirLocation+File.separator+channel; this.filePath = dirLocation+File.separator+channel;
dateFormat = DateTimeFormatter.ofPattern("HH:mm:ss"); File dir = new File(dirLocation);
if (resetFileWriter(false)) try {
this.consistent = true; dir.mkdirs(); // ignore result, because if it's already exists we're good. Otherwise, it will be created. Only issue that can occur is SecurityException thrown, so let's catch it.
} catch (Exception e){
System.out.println("BotFilesWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: \n\t" +e);
return; // consistent = false;
}
if (!dir.exists()) {
System.out.println("BotFilesWorker (@"+server+")->constructor() failed:\n\tUnable to create directory to store files: " + dirLocation); //TODO: notify requester
return;
}
this.consistent = resetFileWriter(false);
} }
private boolean resetFileWriter(boolean reassign){ private boolean resetFileWriter(boolean reassign){
@ -52,7 +56,7 @@ public class BotFilesWorker implements Worker {
return true; return true;
} }
catch (java.io.IOException e){ catch (java.io.IOException e){
System.out.println("Internal issue: BotFilesWorker->constructor() can't create file to store logs: "+this.filePath); System.out.println("BotFilesWorker (@"+ircServer+")->resetFileWriter() failed:\n\tCan't create file to store logs: "+this.filePath);
return false; return false;
} }
} }
@ -66,7 +70,7 @@ public class BotFilesWorker implements Worker {
* argument[1] should be always 'subject' * argument[1] should be always 'subject'
* */ * */
@Override @Override
public void logAdd(String event, String initiatorArg, String messageArg) { public boolean logAdd(String event, String initiatorArg, String messageArg) {
switch (event){ switch (event){
case "PRIVMSG": case "PRIVMSG":
PRIVMSG(initiatorArg, messageArg); PRIVMSG(initiatorArg, messageArg);
@ -96,27 +100,31 @@ public class BotFilesWorker implements Worker {
this.prettyPrint("["+LocalTime.now().format(dateFormat)+"] "+event+" "+initiatorArg+" "+messageArg+"\n"); // TODO: QA @ big data this.prettyPrint("["+LocalTime.now().format(dateFormat)+"] "+event+" "+initiatorArg+" "+messageArg+"\n"); // TODO: QA @ big data
break; break;
} }
} return consistent;
@Override
public void close() {
try {
fileWriter.close();
}
catch (java.io.IOException e){
System.out.println("Internal issue: BotFilesWorker->close() failed\n\tUnable to properly close file: "+this.filePath); // Live with it.
}
} }
private void prettyPrint(String string){ private void prettyPrint(String string){
if (LocalDate.now().isAfter(fileWriterDay)) //if (consistent) { // could be not-opened
resetFileWriter(true); try {
try { if (LocalDate.now().isAfter(fileWriterDay)) {
fileWriter.write(string); if (!resetFileWriter(true)) {
fileWriter.flush(); this.close(); // Error message already printed
} catch (IOException e) { return;
System.out.println("Internal issue: BotFilesWorker->prettyPrint() failed\n\tUnable to write logs of "+this.filePath+" because of internal failure in LocalTime representation."); }
consistent = false; }
} fileWriter.write(string);
fileWriter.flush();
} catch (IOException e) {
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because of internal failure in LocalTime representation.");
this.close();
//consistent = false;
} catch (NullPointerException npe){
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because file descriptor already closed/was not opened.");
consistent = false;
} catch (Exception unknowne){ // ??? No ideas. Just in case. Consider removing.
System.out.println("BotFilesWorker (@" + ircServer + ")->prettyPrint() failed\n\tUnable to write logs of " + this.filePath + " because of exception:\n\t"+unknowne);
this.close();
}
//}
} }
private String genDate(){ private String genDate(){
return "["+LocalTime.now().format(dateFormat)+"] "; return "["+LocalTime.now().format(dateFormat)+"] ";
@ -160,4 +168,16 @@ public class BotFilesWorker implements Worker {
private void TOPIC(String initiatorArg, String messageArg) { private void TOPIC(String initiatorArg, String messageArg) {
this.prettyPrint(genDate()+"-!- "+getUserNameAndHost(initiatorArg)+"has changed topic to: "+messageArg.replaceAll("^.+?:", "")+"\n"); this.prettyPrint(genDate()+"-!- "+getUserNameAndHost(initiatorArg)+"has changed topic to: "+messageArg.replaceAll("^.+?:", "")+"\n");
} }
@Override
public void close() {
try {
if (fileWriter !=null)
fileWriter.close();
}
catch (java.io.IOException e){
System.out.println("BotFilesWorker (@"+ircServer+")->close() failed\n\tUnable to properly close file: "+this.filePath); // Live with it.
}
this.consistent = false;
}
} }

View File

@ -11,17 +11,19 @@ import org.bson.Document;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
/** For each IRC server we create one DB that stored in the hashmap ('static', since we may have few configuration that have to work at once) /** For each IRC server we create one DB that stored in the hashmap ('static', since we may have few configuration that have to work at once)
* For each channel we store collection that have name of the ircServer + chanelName. * For each channel we store collection that have name of the ircServer + chanelName.
* If user decides to use one MongoDB for various servers, he may use even one DB (declared in configuration file) and store collections in there. * If user decides to use one MongoDB for various servers, he may use even one DB (declared in configuration file) and store collections in there.
* **/ * **/
public class BotMongoWorker implements Worker { public class BotMongoWorker implements Worker { //TODO consider skipping checks if server already added.
private static Map<String, MongoClient> serversMap = Collections.synchronizedMap(new HashMap<String, MongoClient>()); private static Map<String, MongoClient> serversMap = Collections.synchronizedMap(new HashMap<String, MongoClient>());
private String ircServer; private String ircServer;
private MongoCollection<Document> collection; private MongoCollection<Document> collection;
private boolean consistent = false; // TODO: clarify possible issues??? private boolean consistent = false;
private boolean isItSystemThread = false; private boolean isItSystemThread = false;
@ -85,7 +87,6 @@ public class BotMongoWorker implements Worker {
@Override @Override
public void serverDescriptionChanged(ServerDescriptionChangedEvent serverDescriptionChangedEvent) { public void serverDescriptionChanged(ServerDescriptionChangedEvent serverDescriptionChangedEvent) {
if (!serverDescriptionChangedEvent.getNewDescription().isOk()) { if (!serverDescriptionChangedEvent.getNewDescription().isOk()) {
consistent = false;
close(ircServer); // ircServer recieved by constructor, not this.ircServer close(ircServer); // ircServer recieved by constructor, not this.ircServer
System.out.println("BotMongoWorker (@"+ircServer+"): ServerListener: Server description changed (exception occurs): " System.out.println("BotMongoWorker (@"+ircServer+"): ServerListener: Server description changed (exception occurs): "
+ serverDescriptionChangedEvent.getNewDescription().getException()); + serverDescriptionChangedEvent.getNewDescription().getException());
@ -96,6 +97,7 @@ public class BotMongoWorker implements Worker {
MongoClientSettings MCS = MongoClientSettings.builder() MongoClientSettings MCS = MongoClientSettings.builder()
// .addCommandListener(mongoCommandListener) // .addCommandListener(mongoCommandListener)
.applyConnectionString(new ConnectionString("mongodb://"+mongoHostAddr)) .applyConnectionString(new ConnectionString("mongodb://"+mongoHostAddr))
.applyToClusterSettings(builder -> builder.serverSelectionTimeout(5, TimeUnit.SECONDS))
.applyToServerSettings(builder -> builder.addServerListener(mongoServerListener)) .applyToServerSettings(builder -> builder.addServerListener(mongoServerListener))
.credential(MongoCredential.createCredential(mongoUser, mongoDBName, mongoPass.toCharArray())) .credential(MongoCredential.createCredential(mongoUser, mongoDBName, mongoPass.toCharArray()))
.build(); .build();
@ -107,30 +109,33 @@ public class BotMongoWorker implements Worker {
MongoDatabase mongoDB = serversMap.get(ircServer).getDatabase(mongoDBName); MongoDatabase mongoDB = serversMap.get(ircServer).getDatabase(mongoDBName);
collection = mongoDB.getCollection(ircServer + channel); collection = mongoDB.getCollection(ircServer + channel);
Document ping = new Document("ping", "1"); Document ping = new Document("ping", 1);
//
try { try {
collection.insertOne(ping); Document answer = mongoDB.runCommand(ping); // reports to monitor thread if some fuckups happens
consistent = true; // if no exceptions, then true if (answer.get("ok") == null || (Double)answer.get("ok") != 1.0d){
close(ircServer);
return;
}
consistent = true;
} catch (MongoCommandException mce){ } catch (MongoCommandException mce){
System.out.println("BotMongoWorker (@"+this.ircServer+"): Command exception. Check if username/password set correctly."); System.out.println("BotMongoWorker (@"+this.ircServer+"): Command exception. Check if username/password set correctly.");
consistent = false;
close(ircServer); // ircServer received by constructor, not this.ircServer close(ircServer); // ircServer received by constructor, not this.ircServer
} catch (MongoTimeoutException mte) { } catch (MongoTimeoutException mte) {
System.out.println("BotMongoWorker (@"+this.ircServer+"): Timeout exception"); System.out.println("BotMongoWorker (@"+this.ircServer+"): Timeout exception.");
consistent = false;
close(ircServer); // ircServer received by constructor, not this.ircServer close(ircServer); // ircServer received by constructor, not this.ircServer
}catch (MongoException me){ }catch (MongoException me){
System.out.println("BotMongoWorker (@"+this.ircServer+"): MongoDB Exception"); System.out.println("BotMongoWorker (@"+this.ircServer+"): MongoDB Exception.");
consistent = false;
close(ircServer); // ircServer received by constructor, not this.ircServer close(ircServer); // ircServer received by constructor, not this.ircServer
} catch (IllegalStateException ise){ } catch (IllegalStateException ise){
System.out.println("BotMongoWorker (@"+this.ircServer+"): Illegal state exception: MongoDB server already closed (not an issue)."); System.out.println("BotMongoWorker (@"+this.ircServer+"): Illegal state exception: MongoDB server already closed (not an issue).");
consistent = false; consistent = false;
// no need to close() obviously
} }
} }
@Override @Override
public void logAdd(String event, String initiatorArg, String messageArg) { public boolean logAdd(String event, String initiatorArg, String messageArg) {
Document document = new Document("date", getDate()) Document document = new Document("date", getDate())
.append("event", event) .append("event", event)
.append("initiator", initiatorArg); .append("initiator", initiatorArg);
@ -163,7 +168,23 @@ public class BotMongoWorker implements Worker {
//preparedStatement.setString(5,null); //preparedStatement.setString(5,null);
break; break;
} }
collection.insertOne(document); // TODO: try/catch and watch try {
collection.insertOne(document); // TODO: call finalize?
consistent = true; // if no exceptions, then true
} catch (MongoCommandException mce){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Command exception. Check if username/password set correctly.");
this.close();
} catch (MongoTimeoutException mte) {
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Timeout exception.");
this.close();
}catch (MongoException me){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): MongoDB Exception.");
this.close();
} catch (IllegalStateException ise){
System.out.println("BotMongoWorker (@"+this.ircServer+")->logAdd(): Illegal state exception: MongoDB server already closed (not an issue).");
this.close();
}
return consistent;
} }
private long getDate(){ return System.currentTimeMillis() / 1000L; } // UNIX time private long getDate(){ return System.currentTimeMillis() / 1000L; } // UNIX time
@ -178,14 +199,16 @@ public class BotMongoWorker implements Worker {
if (this.isItSystemThread && serversMap.containsKey(ircServer)) { if (this.isItSystemThread && serversMap.containsKey(ircServer)) {
serversMap.get(ircServer).close(); serversMap.get(ircServer).close();
serversMap.remove(ircServer); serversMap.remove(ircServer);
System.out.println("BotMongoWorker (@"+this.ircServer+")->close(): " + ircServer); //System.out.println("BotMongoWorker (@"+this.ircServer+")->close()"); // expected exit
} }
consistent = false;
} }
public void close(String server) { private void close(String server) {
if (serversMap.containsKey(server)) { if (serversMap.containsKey(server)) {
serversMap.get(server).close(); serversMap.get(server).close();
serversMap.remove(server); serversMap.remove(server);
System.out.println("BotMongoWorker (@"+this.ircServer+")->close(): " + server + " (forced by listeners)"); System.out.println("BotMongoWorker (@"+this.ircServer+")->close() [forced by listeners]");
} }
consistent = false;
} }
} }

View File

@ -11,16 +11,24 @@ public class BotSQLiteWorker implements Worker {
private Connection connection; private Connection connection;
private boolean consistent = false; private boolean consistent = false;
private PreparedStatement preparedStatement; private PreparedStatement preparedStatement;
private String ircServer;
/** /**
* Don't even think of changing this balalaika. * Don't even think of changing this balalaika.
* */ * */
public BotSQLiteWorker(String server, String[] driverParameters, String channel){ // TODO: threads on SQLite level // remember: One file one DB public BotSQLiteWorker(String server, String[] driverParameters, String channel){ // TODO: threads on SQLite level // remember: One file one DB
this.ircServer = server;
driverParameters[0] = driverParameters[0].trim(); driverParameters[0] = driverParameters[0].trim();
File dir = new File(driverParameters[0]); File dir = new File(driverParameters[0]);
dir.mkdirs(); // TODO: Check if not-null try {
if (!dir.exists()) { dir.mkdirs(); // ignore result, because if it's already exists we're good. Otherwise, it will be created. Only issue that can occur is SecurityException thrown, so let's catch it.
System.out.println("Unable to create directory to store DB file: " + driverParameters[0]); //TODO: notify requester } catch (Exception e){
this.consistent = false; System.out.println("BotSQLiteWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: \n\t" +e);
return; // consistent = false;
}
if (!dir.exists()) { // probably we might want to try-catch SecurityException, but if it appeared, it has been appeared already in previous block
System.out.println("BotSQLiteWorker (@"+server+")->constructor(): Failure:\n\tUnable to create directory to store DB file: " + driverParameters[0]);
return; // consistent = false;
} }
String connectionURL; String connectionURL;
if (driverParameters[0].endsWith(File.separator)) if (driverParameters[0].endsWith(File.separator))
@ -28,7 +36,7 @@ public class BotSQLiteWorker implements Worker {
else else
connectionURL = "jdbc:sqlite:"+driverParameters[0]+File.separator+server+".db"; connectionURL = "jdbc:sqlite:"+driverParameters[0]+File.separator+server+".db";
String safeChanName = channel.trim().replaceAll("\"","\\\""); // TODO: use trim in every driver/worker? channel = channel.trim().replaceAll("\"","\\\""); // TODO: use trim in every driver/worker?
try { try {
SQLiteConfig sqlConfig = new SQLiteConfig(); SQLiteConfig sqlConfig = new SQLiteConfig();
sqlConfig.setOpenMode(SQLiteOpenMode.NOMUTEX); //SQLITE_OPEN_NOMUTEX : multithreaded mode sqlConfig.setOpenMode(SQLiteOpenMode.NOMUTEX); //SQLITE_OPEN_NOMUTEX : multithreaded mode
@ -37,7 +45,7 @@ public class BotSQLiteWorker implements Worker {
if (connection != null){ if (connection != null){
// Create table if not created // Create table if not created
Statement statement = connection.createStatement(); Statement statement = connection.createStatement();
String query = "CREATE TABLE IF NOT EXISTS \""+safeChanName+"\" (" String query = "CREATE TABLE IF NOT EXISTS \""+channel+"\" ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + " id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ " unixtime INTEGER," + " unixtime INTEGER,"
+ " event TEXT," + " event TEXT,"
@ -48,7 +56,7 @@ public class BotSQLiteWorker implements Worker {
statement.executeUpdate(query); statement.executeUpdate(query);
// Check table representation // Check table representation
ResultSet rs = statement.executeQuery("PRAGMA table_info(\""+safeChanName+"\");"); // executeQuery never null ResultSet rs = statement.executeQuery("PRAGMA table_info(\""+channel+"\");"); // executeQuery never null
boolean[] schemaResultCheck = {false, false, false, false, false, false}; boolean[] schemaResultCheck = {false, false, false, false, false, false};
while (rs.next()) { while (rs.next()) {
@ -116,8 +124,8 @@ public class BotSQLiteWorker implements Worker {
// Validating result: it table in DB have expected schema. If not, removing and recreating table. // Validating result: it table in DB have expected schema. If not, removing and recreating table.
for (boolean element: schemaResultCheck) { for (boolean element: schemaResultCheck) {
if (!element) { if (!element) {
System.out.println("BotSQLiteWorker: Found already existing table for channel with incorrect syntax: removing table and re-creating."); System.out.println("BotSQLiteWorker (@"+server+")->Constructor(): Notice:\n\tFound already existing table for channel with incorrect syntax: removing table and re-creating.");
statement.executeUpdate("DROP TABLE \"" + safeChanName + "\";"); statement.executeUpdate("DROP TABLE \"" + channel + "\";");
statement.executeUpdate(query); statement.executeUpdate(query);
break; break;
} }
@ -125,17 +133,18 @@ public class BotSQLiteWorker implements Worker {
this.consistent = true; this.consistent = true;
this.preparedStatement = connection.prepareStatement( this.preparedStatement = connection.prepareStatement(
"INSERT INTO \""+safeChanName "INSERT INTO \""+channel
+"\" (unixtime, event, subject, message, object) " +"\" (unixtime, event, subject, message, object) "
+"VALUES (?, ?, ?, ?, ?);"); +"VALUES (?, ?, ?, ?, ?);");
} }
else { else {
System.out.println("BotSQLiteWorker (@"+server+")->constructor() failed:\n\t Connection to SQLite not established.");
this.consistent = false; this.consistent = false;
} }
} }
catch (SQLException e){ catch (SQLException e){
System.out.println("Internal issue: BotSQLiteWorker->constructor() failed\n\t"+e); System.out.println("BotSQLiteWorker (@"+server+")->constructor() failed:\n\t"+e);
this.consistent = false; this.consistent = false; // this.close();
} }
} }
@ -146,7 +155,7 @@ public class BotSQLiteWorker implements Worker {
public boolean isConsistent() {return consistent; } public boolean isConsistent() {return consistent; }
@Override @Override
public void logAdd(String event, String initiatorArg, String messageArg) { public boolean logAdd(String event, String initiatorArg, String messageArg) {
try { try {
preparedStatement.setLong(1, getDate()); preparedStatement.setLong(1, getDate());
preparedStatement.setString(2, event); preparedStatement.setString(2, event);
@ -182,10 +191,14 @@ public class BotSQLiteWorker implements Worker {
} }
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
} }
catch (SQLException e){ catch (SQLException sqle){
System.out.println("Internal issue: BotSQLiteWorker->logAdd() failed\n\t"+e); System.out.println("BotSQLiteWorker (@"+ircServer+")->logAdd() failed:\n\t"+sqle);
this.consistent = false; this.close(); // consistent will become false. Don't touch this.
}catch (NullPointerException npe){
System.out.println("BotSQLiteWorker (@"+ircServer+")->logAdd() failed:\n\t"+npe);
this.consistent = false; // most likely closed/non-opened file
} }
return consistent;
} }
@Override @Override
@ -194,8 +207,9 @@ public class BotSQLiteWorker implements Worker {
//System.out.println("SQLite drier closed"); //System.out.println("SQLite drier closed");
this.connection.close(); this.connection.close();
} }
catch (SQLException e){ catch (SQLException | NullPointerException e){ //todo: consider redo
System.out.println("Internal issue: BotSQLiteWorker->close() failed\n\t" + e); System.out.println("BotSQLiteWorker (@"+ircServer+")->close() failed:\n\t" + e); // nothing to do here
} }
this.consistent = false;
} }
} }

View File

@ -5,7 +5,7 @@ public class BotZeroWorker implements Worker{
public boolean isConsistent() {return true;} public boolean isConsistent() {return true;}
@Override @Override
public void logAdd(String event, String initiatorArg, String messageArg) {} public boolean logAdd(String event, String initiatorArg, String messageArg) { return true; }
@Override @Override
public void close() {} public void close() {}

View File

@ -5,7 +5,7 @@ public interface Worker {
boolean isConsistent(); boolean isConsistent();
void logAdd(String event, boolean logAdd(String event,
String initiatorArg, String initiatorArg,
String messageArg); String messageArg);

View File

@ -1,54 +0,0 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTest {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "MongoDB", new String[]{"192.168.1.5:27017",
"irc",
"loper",
"password"}))
System.out.println("Successful driver initiation");
else {
System.out.println("Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("LogFile1: "+fw1.isConsistent());
System.out.println("LogFile2: "+fw2.isConsistent());
System.out.println("LogFile3: "+fw3.isConsistent());
fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
fw1.close();
fw2.close();
fw3.close();
}
}
}

View File

@ -0,0 +1,71 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestFiles {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "files", new String[]{"/tmp/logs/"}))
System.out.println("DRVT_Files: Successful driver initiation");
else {
System.out.println("DRVT_Files: Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_Files:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_Files:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_Files:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_Files:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_Files:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Files:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_Files:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}

View File

@ -0,0 +1,73 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestMongo {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "MongoDB", new String[]{"192.168.1.186:27017",
"irc",
"loper",
"password"}))
System.out.println("DRVT_Mongo:Successful driver initiation");
else {
System.out.println("DRVT_Mongo:Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_Mongo:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_Mongo:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_Mongo:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_Mongo:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_Mongo:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_Mongo:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}

View File

@ -0,0 +1,70 @@
package Temporary;
import InnaIrcBot.LogDriver.BotDriver;
import InnaIrcBot.LogDriver.Worker;
public class DriverTestSQLite {
public static void main(String[] args){
if (BotDriver.setLogDriver("irc.tomsk.net", "SQLite", new String[]{"/tmp/logs/mylogs"}))
System.out.println("DRVT_SQLite:Successful driver initiation");
else {
System.out.println("DRVT_SQLite:Failed driver initiation");
return;
}
Worker fw1 = BotDriver.getWorker("irc.tomsk.net","system");
Worker fw2 = BotDriver.getWorker("irc.tomsk.net","#main");
Worker fw3 = BotDriver.getWorker("irc.tomsk.net","#lpr");
if ((fw1 !=null) && (fw2 !=null) && (fw3 !=null)){
System.out.println("DRVT_SQLite:LogFile1: "+fw1.isConsistent());
System.out.println("DRVT_SQLite:LogFile2: "+fw2.isConsistent());
System.out.println("DRVT_SQLite:LogFile3: "+fw3.isConsistent());
boolean res;
res = fw1.logAdd("JOIN", "de_su!loper@desktop.lan", "message1");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw1.logAdd("PART", "de_su!loper@desktop.lan", "#chan1");
System.out.println("DRVT_SQLite:fw1 exec result: "+res);
res = fw2.logAdd("JOIN", "de_su!loper@desktop.lan", "message2");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw2.logAdd("PART", "de_su!loper@desktop.lan", "#chan2");
System.out.println("DRVT_SQLite:fw2 exec result: "+res);
res = fw3.logAdd("JOIN", "de_su!loper@desktop.lan", "message3");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": some text here");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PRIVMSG", "de_su!loper@desktop.lan", ": more random tests");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("NICK", "de_su!loper@desktop.lan", "developer_su");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("MODE", "de_su!loper@desktop.lan", "+b username");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
res = fw3.logAdd("PART", "de_su!loper@desktop.lan", "#chan3");
System.out.println("DRVT_SQLite:fw3 exec result: "+res);
fw1.close();
fw2.close();
fw3.close();
}
}
}