Digital Resilience Pays Off
Download this e-book to learn about the role of Digital Resilience across enterprises.
Speaking of Java as a language as opposed to the JVM platform, James Gosling, the Father of Java, said “Most people talk about Java the language, and this may sound odd coming from me, but I could hardly care less.”
He went on to explain, “What I really care about is the Java Virtual Machine as a concept, because that is the thing that ties it all together.”
– Quoted from theserverside.com
Alternate JVM languages are gaining momentum all over the place. These are languages that are focused on a particular paradigm, semantic ,programming style or perhaps fill a niche roll that is better suited to coding in Java.
We are spoiled for choice with JVM languages .We do not need to get overly religious about “what is the best language” anymore, as so many online debates tend to descend into.I say choose the right tool for the job.You might have a hefty investment in some legacy Java coded librarys , but your new web framework might be written in a more object functional style using Scala, and perhaps a DSL(Domain Specific Language) and your test suites are written in Groovy , all co-existing harmoniously as Java bytecodes executing in the JVM.
The guys at dev.splunk.com have been doing some great work building various language SDK’s over the past few months.
And the Java SDK currently has very thorough Splunk REST endpoint coverage.
What’s great about this is that here you have one SDK that can actually become many when imported and used by other JVM languages.
Here are some trivial examples showing usage of the Java SDK from Groovy and Scala.
Both examples simply connect to the “/server/info” endpoint and dump the server info to STD OUT.
I’m not trying to win any prizes for code elegance here, just enough to show that I’m actually using the mentioned languages( and yes, the examples DO compile and run)
import com.splunk.Service._
import scala.collection.mutable.HashMap
import scala.collection.JavaConversions._
object SplunkJavaSDKWrapper {
def main(args: Array[String]) = {
//Connection to Service
val connectionArgs = HashMap[String, Object]("host"->"somehost","username" -> "fred","password" ->"sweetmoves" )
val service = connect(connectionArgs)
//get Splunk Server info
val info = service.getInfo
//Scala/Java Set conversion
val javaSet = info.keySet
val scalaSet = javaSet.toSet
//print out Splunk Server info
for(key <- scalaSet)
println(key+":"+info.get(key))
}
}
import com.splunk.Entity;
import com.splunk.Service;
import com.splunk.ServiceInfo;
import com.splunk.sdk.Command;
class SplunkJavaSDKWrapper {
//groovy map
static def splunkInfo = [:]
static main(args) {
//read in settings from .splunkrc
Command command = Command.splunk()
Service service = Service.connect(command.opts)
//get Splunk Server info
ServiceInfo info = service.getInfo()
for (key in info.keySet())
splunkInfo.put(key,info.get(key))
printSplunkInfo()
}
//print out Splunk Server info
static printSplunkInfo() {
println "Info"
splunkInfo.each { key, value ->println key + " : " + value}
}
}
----------------------------------------------------
Thanks!
Damien Dallimore
The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are secure, resilient and innovative.
Founded in 2003, Splunk is a global company — with over 7,500 employees, Splunkers have received over 1,020 patents to date and availability in 21 regions around the world — and offers an open, extensible data platform that supports shared data across any environment so that all teams in an organization can get end-to-end visibility, with context, for every interaction and business process. Build a strong data foundation with Splunk.