Skip to content

Instantly share code, notes, and snippets.

View HDBandit's full-sized avatar

Gerard Vico HDBandit

View GitHub Profile
object Color {
def create(r: Int, g: Int, b: Int): Color = {
new Color(r, g, b)
}
}
class Color(r: Int, g: Int, b: Int) {
object ApplicationMain extends App {
val system = ActorSystem("MyActorSystem")
val pongActor = system.actorOf(Pong.props, "pongActor")
pongActor ! PongMessage("Initial message")
// waiting for JMX "end" message to terminate
system.awaitTermination()
}
class Pong extends ActorWithJMXSupport with ActorLogging with PongMBean{
import Pong._
var lastReceivedMessage = "UNKNOWN"
def receive = {
case PongMessage(text) =>
log.info("In PongActor - received message: {}", text)
lastReceivedMessage = text
}
trait PongMBean {
def lastReceivedMessage(): String
def sendMessage(p1: String): Unit
}
trait ActorWithJMXSupport extends Actor {
val mBeanServer = ManagementFactory.getPlatformMBeanServer();
val objName = new ObjectName("hdbandit", {
import scala.collection.JavaConverters._
new java.util.Hashtable(
Map(
"name" -> self.path.toStringWithoutAddress,
"type" -> getMXTypeName
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
@RestController
@RequestMapping("/example")
@RefreshScope
public class ExampleService {
@Value("${message.hello}")
private String message;
@RequestMapping(method = RequestMethod.GET)
public String getExample() {
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
@RestController
@RequestMapping("/example")
@RefreshScope
public class ExampleService {
@Value("${message.hello}")
private String message;
@RequestMapping(method = RequestMethod.GET)
public String getExample() {
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}