Ramblings

25 Aug, 2009

Using jnp as a JBoss heartbeat

Posted by: Matt Williams In: Computers| jboss| jruby

jnp is a JBoss protocol which exposes jndi.  It is, by default, bound to port 1099.  I’d been using that port as a heartbeat, but “cheating” — I would open a socket and then close it immediately.  However, this caused problems.  jnp is chatty.  And it got upset at my not letting it say ‘hi’ before I dropped the connection.   So, here’s a code snippet (jruby, the Java should be an exercise for the student) which allows you to actually do an intelligent check.

  def check_port(server)
    @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port})"
    begin

      env = java.util.Properties.new();
      env.set_property("java.naming.factory.initial",
                       "org.jnp.interfaces.NamingContextFactory");
      env.set_property("java.naming.provider.url",
                       "#{server.host}:#{server.port}");
      ctx = javax.naming.InitialContext.new(env);

      # if the server is not running, we'll get an error here because
      # it will timeout.
      ctx.list("")
      ctx.close
      @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port}): Succeeded"
    rescue javax.naming.CommunicationException => comm_error
      @logger.debug "check_port: #{server.fqdn}(#{server.host}:#{server.port}): Not Running"
      begin
        ctx.close
      rescue Exception => ignore_me
      end
      return false

    rescue Exception => e2
      @logger.info "check_port: #{server.fqdn}(#{server.host}:#{server.port}): FAILED: #{e2.to_s}"
      return false
    end
    return true
  end
Enhanced by Zemanta

No Responses to "Using jnp as a JBoss heartbeat"

Comment Form

Categories

DrakNet Web Hosting

  • Geoffrey Ducharme: Excellent points. I've taken to heart to purposefully disconnect myself from the Internet, in order to be more attentive to what I'm doing at the mome
  • Shared Frank: A fully explained article! Well done, I found this blog on google and found very intresting. Thanks and bookmarked
  • abby williams: okay, so i randomly click on an email. it takes me to this... now i realize just how big a geek my big bro is, and that i will never learn to understa

Flickr PhotoStream

    layout_newm3headerTerrain Testa

About

Matt Williams is a geekly jack of all trades residing in Columbus, OH, USA.

Recommend Me


Adopt a Dragon from Dragcave
Adopt one today!Adopt one today!Adopt one today!Adopt one today! Adopt one today! Adopt one today!Adopt one today! Adopt one today! Adopt one today! Adopt one today!