This file contains hidden or 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
| { | |
| "_id" : "shard01", | |
| "host" : "shard01/localhost:27018,localhost:27019,localhost:27020" | |
| } |
This file contains hidden or 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
| def parseShardInformation(item: Document): Shard = { | |
| val document = item.toBsonDocument | |
| val shardId = document.getString("_id").getValue | |
| val serversDefinition = document.getString("host").getValue | |
| val servers = if (serversDefinition.contains("/")) serversDefinition.substring(serversDefinition.indexOf('/') + 1) else serversDefinition | |
| Shard(shardId, "mongodb://" + servers) | |
| } |
This file contains hidden or 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
| val shards = client.getDatabase("config") | |
| .getCollection("shards") | |
| .find() | |
| .map(parseShardInformation) |
This file contains hidden or 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
| def source(client: MongoClient): Source[Document, NotUsed] = { | |
| val observable = client.getDatabase("local") | |
| .getCollection("oplog.rs") | |
| .find(and( | |
| in("op", "i", "d", "u"), | |
| exists("fromMigrate", false))) | |
| .cursorType(CursorType.TailableAwait) | |
| .noCursorTimeout(true) | |
| Source.fromPublisher(observable) |
This file contains hidden or 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
| val allShards: Source[Document, NotUsed] = | |
| sources.foldLeft(Source.empty[Document]) { | |
| (prev, current) => Source.combine(prev, current)(Merge(_)) | |
| } | |
| allShards.runForeach(println) |
This file contains hidden or 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
| val sourceOne = Source(List(1)) | |
| val sourceTwo = Source(List(2)) | |
| val merged = Source.combine(sourceOne, sourceTwo)(Merge(_)) |
This file contains hidden or 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
| client.getDatabase("local") | |
| .getCollection("oplog.rs") | |
| .find(and( | |
| in(MongoConstants.OPLOG_OPERATION, "i", "d", "u"), | |
| exists("fromMigrate", false))) | |
| .cursorType(CursorType.TailableAwait) | |
| .noCursorTimeout(true) |
This file contains hidden or 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
| def doSomethingImportant() = { | |
| val timer = registry.timer(name(classOf[WebProxy], "get-requests")) | |
| val context = timer.time() | |
| try // critical business logic | |
| finally context.stop() | |
| } |
This file contains hidden or 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
| @Timed | |
| def doSomethingImportant = { | |
| // critical business logic | |
| } |
This file contains hidden or 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
| @Timed | |
| class SuperCriticalFunctionality { | |
| def doSomethingImportant = { | |
| // critical business logic | |
| } | |
| } |