forked from avvero/longo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,876 additions
and
222 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
class BootStrap { | ||
|
||
def socketEventService | ||
def mongoEventService | ||
|
||
def init = { servletContext -> | ||
// socketLogService.start() | ||
// mongoEventService.start() | ||
|
||
} | ||
def destroy = { | ||
// socketLogService.stop() | ||
// mongoEventService.stop() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,9 @@ class Socket { | |
|
||
static constraints = { | ||
} | ||
|
||
def getKey() { | ||
return "socket:" + this.host+":" + this.port | ||
} | ||
|
||
} |
34 changes: 0 additions & 34 deletions
34
grails-app/services/com/avvero/longo/SocketEventService.groovy
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.avvero.longo | ||
|
||
import com.mongodb.DBObject | ||
import org.apache.commons.logging.LogFactory | ||
import org.apache.log4j.spi.LoggingEvent | ||
import org.atmosphere.cpr.Broadcaster | ||
import org.log4mongo.LoggingEventBsonifier | ||
import org.log4mongo.LoggingEventBsonifierImpl | ||
|
||
/** | ||
* | ||
* @author fxdev-belyaev-ay | ||
*/ | ||
class SocketCollector extends Collector { | ||
|
||
private static final log = LogFactory.getLog(this) | ||
|
||
Socket socket | ||
ServerSocket serverSocket | ||
|
||
LoggingEventBsonifier bsonifier = new LoggingEventBsonifierImpl() | ||
|
||
SocketCollector (Socket socket) { | ||
this.socket = socket | ||
} | ||
|
||
@Override | ||
String getName() { | ||
return socket.getKey() | ||
} | ||
|
||
@Override | ||
void _start() { | ||
log.info("Start SocketCollector...") | ||
log.info("Listening on port " + socket.port); | ||
serverSocket = new ServerSocket(socket.port); | ||
new Thread(new Runnable() { | ||
@Override | ||
void run() { | ||
log.info("Waiting to accept a new client."); | ||
java.net.Socket serverSocket = serverSocket.accept(); | ||
log.info("Connected to client at " + getName()); | ||
log.info("Starting new socket node."); | ||
ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(serverSocket.getInputStream())); | ||
try { | ||
LoggingEvent event; | ||
if (ois != null) { | ||
while(true) { | ||
// read an event from the wire | ||
event = (LoggingEvent) ois.readObject(); | ||
alertListener(event) | ||
} | ||
} | ||
} finally { | ||
if (ois != null) { | ||
try { | ||
ois.close(); | ||
} catch(Exception e) { | ||
log.info("Could not close connection.", e); | ||
} | ||
} | ||
if (socket != null) { | ||
try { | ||
socket.close(); | ||
} catch(InterruptedIOException e) { | ||
Thread.currentThread().interrupt(); | ||
} catch(IOException ex) { | ||
} | ||
} | ||
} | ||
} | ||
}).start() | ||
} | ||
|
||
@Override | ||
void _stop() { | ||
log.info("Stop SocketCollector...") | ||
serverSocket.close() | ||
} | ||
|
||
@Override | ||
protected Listener getNewListener(Broadcaster broadcaster) { | ||
return new Listener() { | ||
void handle(Object o) { | ||
LoggingEvent event = (LoggingEvent) o; | ||
DBObject bson = bsonifier.bsonify(event); | ||
def log = bson.toString() | ||
broadcaster.broadcast(log) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.