Skip to content

Instantly share code, notes, and snippets.

@coreypurcell
Created September 10, 2011 20:41
Show Gist options
  • Save coreypurcell/1208749 to your computer and use it in GitHub Desktop.
Save coreypurcell/1208749 to your computer and use it in GitHub Desktop.

Revisions

  1. coreypurcell revised this gist Sep 11, 2011. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,9 @@ def connect(cluster, &blk)
    # calling super(cluster) produces an error in the CodeGenUtils java class
    # -- so hacking around it
    # oddly just renaming my method to rconnect and calling the super's connect
    # method works just fine
    # method works just fine ex:
    # def rconnect(cluster, &blk)
    # connect(cluster)
    org.jgroups.JChannel.instance_method(:connect).bind(self).call(cluster)
    @receiver.register_receiver(blk)
    end
  2. coreypurcell revised this gist Sep 11, 2011. 1 changed file with 17 additions and 17 deletions.
    34 changes: 17 additions & 17 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,33 @@
    class Channel
    class Channel < org.jgroups.JChannel

    extend Forwardable
    alias_method :old_send, :send

    def_delegators :@jchannel, :close

    def initialize(options=nil)
    if options
    @jchannel = org.jgroups.JChannel.new(options)
    else
    @jchannel = org.jgroups.JChannel.new
    end
    def initialize
    super
    # if options
    # @jchannel = org.jgroups.JChannel.new(options)
    # else
    # @jchannel = org.jgroups.JChannel.new
    # end

    @receiver = Receiver.new
    @jchannel.setReceiver(@receiver)
    set_receiver(@receiver)
    end

    def connect(cluster, &blk)
    @jchannel.connect(cluster)
    # calling super(cluster) produces an error in the CodeGenUtils java class
    # -- so hacking around it
    # oddly just renaming my method to rconnect and calling the super's connect
    # method works just fine
    org.jgroups.JChannel.instance_method(:connect).bind(self).call(cluster)
    @receiver.register_receiver(blk)
    end

    def send(msg, options={})
    destination = options[:destination]
    source = options[:source]
    message = Message.new(destination,source,msg)
    @jchannel.send(message)
    super(message)
    end

    def method_missing(method, *args, &block)
    @jchannel.send(method, *args)
    end
    end
    end
  3. coreypurcell created this gist Sep 10, 2011.
    33 changes: 33 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    class Channel

    extend Forwardable

    def_delegators :@jchannel, :close

    def initialize(options=nil)
    if options
    @jchannel = org.jgroups.JChannel.new(options)
    else
    @jchannel = org.jgroups.JChannel.new
    end

    @receiver = Receiver.new
    @jchannel.setReceiver(@receiver)
    end

    def connect(cluster, &blk)
    @jchannel.connect(cluster)
    @receiver.register_receiver(blk)
    end

    def send(msg, options={})
    destination = options[:destination]
    source = options[:source]
    message = Message.new(destination,source,msg)
    @jchannel.send(message)
    end

    def method_missing(method, *args, &block)
    @jchannel.send(method, *args)
    end
    end