Skip to content

Instantly share code, notes, and snippets.

View write2munish's full-sized avatar

Munish Gupta write2munish

View GitHub Profile
@write2munish
write2munish / gist:76305b564b2a74a01264
Last active November 24, 2015 10:18
Vert.x verticle publishing Hystrix metrics as stream
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
router.get("/service/hystrix.stream").handler(this::hystrixStream);
vertx.createHttpServer().requestHandler(router::accept).listen(8090);
public void hystrixStream(RoutingContext ctx) {
//set the header parameters
ctx.response().setChunked(true);
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@write2munish
write2munish / PingPong.java
Created May 22, 2012 06:44
Java Threading Synchronization example
public class PingPong {
Agent<String> whoseTurn;
public PingPong(Agent<String> player) {
whoseTurn = player;
}
public boolean hit(final String opponent) {
final String x = Thread.currentThread().getName();
@write2munish
write2munish / PingPong.java
Created May 22, 2012 06:30
Java Threading Synchronization example
public class PingPong {
//updates to Ref.View are synchronous
Ref.View<String> whoseTurn;
public PingPong(Ref.View<String> player) {
whoseTurn = player;
}
public boolean hit(final String opponent) {
@write2munish
write2munish / Game.java
Created May 22, 2012 06:22
Java Threading Synchronization example
public class Game {
public static void main(String args[]) {
PingPong table = new PingPong();
Thread alice = new Thread(new Player("bob", table));
Thread bob = new Thread(new Player("alice", table));
alice.setName("alice");
bob.setName("bob");
alice.start(); // alice starts playing
bob.start(); // bob starts playing
@write2munish
write2munish / PingPong.java
Created May 22, 2012 06:16
Java Threading Synchronization example
public class PingPong {
// state variable identifying whose turn it is.
private String whoseTurn = null;
public synchronized boolean hit(String opponent) {
String x = Thread.currentThread().getName();
if (x.compareTo(whoseTurn) == 0) {
System.out.println("PING! (" + x + ")");
@write2munish
write2munish / Player.java
Created May 22, 2012 06:13
Java Threading Synchronization example
public class Player implements Runnable {
PingPong myTable; // Table where they play
String myOpponent;
public Player(String opponent, PingPong table) {
myTable = table;
myOpponent = opponent;
}
public void run() {
@write2munish
write2munish / Omnifind.java
Created May 16, 2012 06:56
Using OmniFind search in Portal Applications
// create a valid Application ID that will be used
// by the Search Node to authorize access to the collection
ApplicationInfo appinfo = factory.createApplicationInfo(applicationName);
appinfo.setPassword(applicationPassword);
// create a new Properties object.
Properties config = new Properties();
config.setProperty("hostname", "OmniFindHostName");
config.setProperty("port", "80");
config.setProperty("timeout", "60");
@Test
public void testEchoActor() {
ActorRef echoActorRef = _system.actorOf(new Props(EchoActor.class));
// pass the reference to implicit sender testActor() otherwise
// message end up in dead mailbox
echoActorRef.tell("Hi there", super.testActor());
expectMsg("Hi there");
}
@Test