Skip to content
Permalink
Browse files

Added management for getting info about the running neo4j instance or…

… cluster [#143 state:resolved]

Example: Neo4j.management.get_number_of_node_ids_in_use
  • Loading branch information...
andreasronge committed Feb 9, 2011
1 parent d8e0156 commit 1c59b6dbf0e51f708574697ef7278cafdef1b597
Showing with 44 additions and 6 deletions.
  1. +1 −1 lib/neo4j.rb
  2. +7 −0 lib/neo4j/database.rb
  3. +27 −0 lib/neo4j/neo4j.rb
  4. +9 −5 spec/neo4j_spec.rb
@@ -15,6 +15,7 @@
require 'neo4j/jars/core/lucene-core-3.0.3.jar'
require 'neo4j/jars/core/neo4j-lucene-index-0.5-1.3.M01.jar'
require 'neo4j/jars/core/neo4j-kernel-1.3-1.3.M01.jar'
require 'neo4j/jars/ha/neo4j-management-1.3-1.3.M01.jar'

module Neo4j

@@ -31,7 +32,6 @@ def self.load_shell_jars
def self.load_ha_jars
require 'neo4j/jars/ha/log4j-1.2.16.jar'
require 'neo4j/jars/ha/neo4j-ha-0.6-1.3.M01.jar'
require 'neo4j/jars/ha/neo4j-management-1.3-1.3.M01.jar'
require 'neo4j/jars/ha/netty-3.2.1.Final.jar'
require 'neo4j/jars/ha/org.apache.servicemix.bundles.jline-0.9.94_1.jar'
require 'neo4j/jars/ha/org.apache.servicemix.bundles.lucene-3.0.1_2.jar'
@@ -102,10 +102,17 @@ def shutdown #:nodoc:
@graph = nil
@lucene = nil
@running = false
@neo4j_manager = nil
end

end


def management(jmx_clazz) #:nodoc:
@neo4j_manager ||= org.neo4j.management.Neo4jManager.new(@graph.get_management_bean(org.neo4j.management.Kernel.java_class))
@neo4j_manager.getBean(jmx_clazz.java_class)
end

def begin_tx #:nodoc:
@graph.begin_tx
end
@@ -110,6 +110,33 @@ def ref_node(this_db = self.started_db)
this_db.graph.reference_node
end

# Returns a Management JMX Bean.
#
# Notice that this information is also provided by the jconsole Java tool, check http://wiki.neo4j.org/content/Monitoring_and_Deployment
# and http://docs.neo4j.org/chunked/milestone/operations-monitoring.html
#
# By default it returns the Primitivies JMX Bean that can be used to find number of nodes in use.
#
# ==== Example Neo4j Primititives
#
# Neo4j.management.get_number_of_node_ids_in_use
# Neo4j.management.getNumberOfPropertyIdsInUse
# Neo4j.management.getNumberOfRelationshipIdsInUse
# Neo4j.management.get_number_of_relationship_type_ids_in_use
#
# ==== Example Neo4j HA Cluster Info
#
# Neo4j.management(org.neo4j.management.HighAvailability).isMaster
#
# ==== Arguments
#
# jmx_clazz :: http://api.neo4j.org/current/org/neo4j/management/package-summary.html
# this_db :: default currently runnig instance or a newly started neo4j db instance
#
def management(jmx_clazz = org.neo4j.management.Primitives, this_db = self.started_db)
this_db.management(jmx_clazz)
end

# Returns an Enumerable object for all nodes in the database
def all_nodes(this_db = self.started_db)
Enumerator.new(this_db, :each_node)
@@ -11,21 +11,25 @@
a = Neo4j::Node.new
b = Neo4j::Node.new
a.outgoing(:jo) << b
lambda {Neo4j.ref_node.outgoing(:skoj) << a << b}.should change(Neo4j.ref_node.rels, :size).by(2)
lambda { Neo4j.ref_node.outgoing(:skoj) << a << b }.should change(Neo4j.ref_node.rels, :size).by(2)

lambda {a.del; b.del}.should change(Neo4j.ref_node.rels, :size).by(-2)
lambda { a.del; b.del }.should change(Neo4j.ref_node.rels, :size).by(-2)
end


it "#all_nodes returns a Enumerable of all nodes in the graph database " do
# given created three nodes in a clean database
created_nodes = 3.times.map{ Neo4j::Node.new.id }
created_nodes = 3.times.map { Neo4j::Node.new.id }

# when
found_nodes = Neo4j.all_nodes.map {|node| node.id}
found_nodes = Neo4j.all_nodes.map { |node| node.id }

# then
found_nodes.should include(*created_nodes)
found_nodes.should include(Neo4j.ref_node.id)
end
end

it "#management returns by default a management for Primitives" do
(Neo4j.management.get_number_of_node_ids_in_use > 0).should be true
end
end

0 comments on commit 1c59b6d

Please sign in to comment.
You can’t perform that action at this time.