예제 #1
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
    @JRubyMethod
    public IRubyObject close(ThreadContext context, IRubyObject deregister) {
      Ruby runtime = context.getRuntime();
      this.closed = runtime.getTrue();

      if (deregister == runtime.getTrue()) {
        selector.callMethod(context, "deregister", io);
      }

      return context.nil;
    }
예제 #2
0
 @JRubyMethod(name = {"eof", "eof?"})
 public IRubyObject eof(ThreadContext context) {
   checkReadable();
   Ruby runtime = context.runtime;
   if (ptr.pos < ptr.string.size()) return runtime.getFalse();
   return runtime.getTrue();
 }
예제 #3
0
 /**
  * Take the boolean value and convert it to its bytes.
  *
  * @param bool The Ruby boolean value.
  * @return The byte array.
  * @since 2.0.0
  */
 private static RubyString toBsonBoolean(final IRubyObject bool) {
   final Ruby runtime = bool.getRuntime();
   if (bool == runtime.getTrue()) {
     return RubyString.newString(runtime, TRUE_BYTES);
   } else {
     return RubyString.newString(runtime, FALSE_BYTES);
   }
 }
예제 #4
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
    @JRubyMethod(name = {"writable?", "writeable?"})
    public IRubyObject writable(ThreadContext context) {
      Ruby runtime = context.getRuntime();
      int readyOps = this.key.readyOps();

      if ((readyOps & SelectionKey.OP_WRITE) != 0 || (readyOps & SelectionKey.OP_CONNECT) != 0) {
        return runtime.getTrue();
      } else {
        return runtime.getFalse();
      }
    }
예제 #5
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
    @JRubyMethod(name = "readable?")
    public IRubyObject isReadable(ThreadContext context) {
      Ruby runtime = context.getRuntime();
      int readyOps = this.key.readyOps();

      if ((readyOps & SelectionKey.OP_READ) != 0 || (readyOps & SelectionKey.OP_ACCEPT) != 0) {
        return runtime.getTrue();
      } else {
        return runtime.getFalse();
      }
    }
예제 #6
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
    @JRubyMethod(name = "registered?")
    public IRubyObject isRegistered(ThreadContext context, IRubyObject io) {
      Ruby runtime = context.getRuntime();
      Channel rawChannel = RubyIO.convertToIO(context, io).getChannel();

      if (!(rawChannel instanceof SelectableChannel)) {
        throw runtime.newArgumentError("not a selectable IO object");
      }

      SelectableChannel channel = (SelectableChannel) rawChannel;
      SelectionKey key = channel.keyFor(this.selector);

      if (key == null) return context.nil;

      if (((Monitor) key.attachment()).isClosed(context) == runtime.getTrue()) {
        return runtime.getFalse();
      } else {
        return runtime.getTrue();
      }
    }
예제 #7
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
 @JRubyMethod(name = "empty?")
 public IRubyObject isEmpty(ThreadContext context) {
   Ruby runtime = context.getRuntime();
   return this.selector.keys().isEmpty() ? runtime.getTrue() : runtime.getFalse();
 }
예제 #8
0
파일: Nio4r.java 프로젝트: tpetchel/nio4r
 @JRubyMethod(name = "closed?")
 public IRubyObject isClosed(ThreadContext context) {
   Ruby runtime = context.getRuntime();
   return this.selector.isOpen() ? runtime.getFalse() : runtime.getTrue();
 }
예제 #9
0
  private IRubyObject unmarshalObjectDirectly(int type, MarshalState state, boolean callProc)
      throws IOException {
    IRubyObject rubyObj = null;
    switch (type) {
      case 'I':
        MarshalState childState = new MarshalState(true);
        rubyObj = unmarshalObject(childState);
        if (childState.isIvarWaiting()) {
          defaultVariablesUnmarshal(rubyObj);
        }
        return rubyObj;
      case '0':
        rubyObj = runtime.getNil();
        break;
      case 'T':
        rubyObj = runtime.getTrue();
        break;
      case 'F':
        rubyObj = runtime.getFalse();
        break;
      case '"':
        rubyObj = RubyString.unmarshalFrom(this);
        break;
      case 'i':
        rubyObj = RubyFixnum.unmarshalFrom(this);
        break;
      case 'f':
        rubyObj = RubyFloat.unmarshalFrom(this);
        break;
      case '/':
        rubyObj = RubyRegexp.unmarshalFrom(this);
        break;
      case ':':
        rubyObj = RubySymbol.unmarshalFrom(this);
        break;
      case '[':
        rubyObj = RubyArray.unmarshalFrom(this);
        break;
      case '{':
        rubyObj = RubyHash.unmarshalFrom(this, false);
        break;
      case '}':
        // "hashdef" object, a hash with a default
        rubyObj = RubyHash.unmarshalFrom(this, true);
        break;
      case 'c':
        rubyObj = RubyClass.unmarshalFrom(this);
        break;
      case 'm':
        rubyObj = RubyModule.unmarshalFrom(this);
        break;
      case 'e':
        RubySymbol moduleName = (RubySymbol) unmarshalObject();
        RubyModule tp = null;
        try {
          tp = runtime.getClassFromPath(moduleName.asJavaString());
        } catch (RaiseException e) {
          if (runtime.getModule("NameError").isInstance(e.getException())) {
            throw runtime.newArgumentError("undefined class/module " + moduleName.asJavaString());
          }
          throw e;
        }

        rubyObj = unmarshalObject();

        tp.extend_object(rubyObj);
        tp.callMethod(runtime.getCurrentContext(), "extended", rubyObj);
        break;
      case 'l':
        rubyObj = RubyBignum.unmarshalFrom(this);
        break;
      case 'S':
        rubyObj = RubyStruct.unmarshalFrom(this);
        break;
      case 'o':
        rubyObj = defaultObjectUnmarshal();
        break;
      case 'u':
        rubyObj = userUnmarshal(state);
        break;
      case 'U':
        rubyObj = userNewUnmarshal();
        break;
      case 'C':
        rubyObj = uclassUnmarshall();
        break;
      default:
        throw getRuntime().newArgumentError("dump format error(" + (char) type + ")");
    }

    if (callProc) {
      return doCallProcForObj(rubyObj);
    }

    return rubyObj;
  }