Package org.jruby.pg.internal.messages

Examples of org.jruby.pg.internal.messages.NotificationResponse


    /******     PG::Connection INSTANCE METHODS: NOTIFY     ******/

    @JRubyMethod
    public IRubyObject notifies(ThreadContext context) {
      NotificationResponse notification = postgresqlConnection.notifications();
      if (notification == null)
        return context.nil;
      RubyHash hash = new RubyHash(context.runtime);

      RubySymbol relname = context.runtime.newSymbol("relname");
      RubySymbol pid = context.runtime.newSymbol("be_pid");
      RubySymbol extra = context.runtime.newSymbol("extra");

      hash.op_aset(context, relname, context.runtime.newString(notification.getCondition()));
      hash.op_aset(context, pid, context.runtime.newFixnum(notification.getPid()));
      hash.op_aset(context, extra, context.runtime.newString(notification.getPayload()));

      return hash;
    }
View Full Code Here


    }

    @JRubyMethod(name = {"wait_for_notify", "notifies_wait"}, optional = 1)
    public IRubyObject wait_for_notify(ThreadContext context, IRubyObject[] args, Block block) {
      try {
        NotificationResponse notification = postgresqlConnection.waitForNotify();
        if (block.isGiven()) {
          if (block.arity() == Arity.NO_ARGUMENTS) return block.call(context);
          RubyString condition = context.runtime.newString(notification.getCondition());
          RubyFixnum pid = context.runtime.newFixnum(notification.getPid());
          String javaPayload = notification.getPayload();
          IRubyObject payload = javaPayload == null ? context.nil : context.runtime.newString(javaPayload);
          if (!block.arity().isFixed()) {
            return block.call(context, condition, pid, payload);
          } else if (block.arity().required() == 2) {
            return block.call(context, condition, pid);
          } else if (block.arity().required() == 3) {
            return block.call(context, condition, pid, payload);
          }
          throw context.runtime.newArgumentError("Expected a block with arity 2 or 3");
        } else {
          return context.runtime.newString(notification.getCondition());
        }
      } catch (IOException e) {
        throw newPgError(context, e.getLocalizedMessage(), null, getClientEncodingAsJavaEncoding(context));
      }
    }
View Full Code Here

TOP

Related Classes of org.jruby.pg.internal.messages.NotificationResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.