Example #1
0
  public static RubyClass createPointerClass(Ruby runtime, RubyModule module) {
    RubyClass pointerClass =
        module.defineClassUnder(
            "Pointer",
            module.getClass(AbstractMemory.ABSTRACT_MEMORY_RUBY_CLASS),
            RubyInstanceConfig.REIFY_RUBY_CLASSES
                ? new ReifyingAllocator(Pointer.class)
                : PointerAllocator.INSTANCE);

    pointerClass.defineAnnotatedMethods(Pointer.class);
    pointerClass.defineAnnotatedConstants(Pointer.class);
    pointerClass.setReifiedClass(Pointer.class);
    pointerClass.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof Pointer && super.isKindOf(obj, type);
          }
        };

    module.defineClassUnder(
        "NullPointerError", runtime.getRuntimeError(), runtime.getRuntimeError().getAllocator());

    // Add Pointer::NULL as a constant
    Pointer nullPointer = new Pointer(runtime, pointerClass, new NullMemoryIO(runtime));
    pointerClass.setConstant("NULL", nullPointer);

    runtime
        .getNilClass()
        .addMethod("to_ptr", new NilToPointerMethod(runtime.getNilClass(), nullPointer));

    return pointerClass;
  }
Example #2
0
  @Override
  public RubySymbol execute(VirtualFrame frame) {
    notDesignedForCompilation();

    final Object receiverObject = receiver.execute(frame);

    final RubyMethod methodObject = (RubyMethod) method.execute(frame);

    RubyModule module;

    if (receiverObject instanceof RubyModule) {
      module = (RubyModule) receiverObject;
    } else {
      module = ((RubyBasicObject) receiverObject).getSingletonClass(this);
    }

    final RubyMethod methodWithDeclaringModule = methodObject.withDeclaringModule(module);

    if (moduleFunctionFlag(frame)) {
      module.addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PRIVATE));
      module
          .getSingletonClass(this)
          .addMethod(this, methodWithDeclaringModule.withVisibility(Visibility.PUBLIC));
    } else {
      module.addMethod(this, methodWithDeclaringModule);
    }

    return getContext().newSymbol(method.getName());
  }
Example #3
0
  /** Create the ObjectSpace module and add it to the Ruby runtime. */
  public static RubyModule createObjectSpaceModule(Ruby runtime) {
    RubyModule objectSpaceModule = runtime.defineModule("ObjectSpace");
    runtime.setObjectSpaceModule(objectSpaceModule);

    objectSpaceModule.defineAnnotatedMethods(RubyObjectSpace.class);

    return objectSpaceModule;
  }
Example #4
0
  public static RubyModule createComparable(Ruby runtime) {
    RubyModule comparableModule = runtime.defineModule("Comparable");
    runtime.setComparable(comparableModule);

    comparableModule.defineAnnotatedMethods(RubyComparable.class);

    return comparableModule;
  }
Example #5
0
 public static void createRubyDescriptor(Ruby runtime) {
   RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
   RubyClass cDescriptor =
       protobuf.defineClassUnder(
           "Descriptor",
           runtime.getObject(),
           new ObjectAllocator() {
             @Override
             public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
               return new RubyDescriptor(runtime, klazz);
             }
           });
   cDescriptor.includeModule(runtime.getEnumerable());
   cDescriptor.defineAnnotatedMethods(RubyDescriptor.class);
 }
Example #6
0
  @Override
  public Object execute(VirtualFrame frame) {
    // TODO(cs): can module ever not evaluate to a RubyModule?

    final RubyModule moduleObject = (RubyModule) module.execute(frame);

    final Object rhsValue = rhs.execute(frame);

    assert rhsValue != null;
    assert !(rhsValue instanceof String);

    moduleObject.setModuleConstant(name, rhsValue);

    return rhsValue;
  }
Example #7
0
  public static IRubyObject inheritanceSearchConst(
      ThreadContext context,
      IRubyObject cmVal,
      MutableCallSite site,
      String constName,
      boolean noPrivateConsts)
      throws Throwable {
    Ruby runtime = context.runtime;
    RubyModule module;

    if (cmVal instanceof RubyModule) {
      module = (RubyModule) cmVal;
    } else {
      throw runtime.newTypeError(cmVal + " is not a type/class");
    }

    IRubyObject constant =
        noPrivateConsts
            ? module.getConstantFromNoConstMissing(constName, false)
            : module.getConstantNoConstMissing(constName);

    if (constant == null) {
      constant = UndefinedValue.UNDEFINED;
    }

    SwitchPoint switchPoint = (SwitchPoint) runtime.getConstantInvalidator(constName).getData();

    // bind constant until invalidated
    MethodHandle target = Binder.from(site.type()).drop(0, 2).constant(constant);
    MethodHandle fallback =
        Binder.from(site.type())
            .append(site, constName)
            .append(noPrivateConsts)
            .invokeStatic(LOOKUP, Bootstrap.class, "inheritanceSearchConst");

    // test that module is same as before
    MethodHandle test =
        Binder.from(site.type().changeReturnType(boolean.class))
            .drop(0, 1)
            .insert(1, module.id)
            .invokeStaticQuiet(LOOKUP, Bootstrap.class, "testArg0ModuleMatch");
    target = guardWithTest(test, target, fallback);
    site.setTarget(switchPoint.guardWithTest(target, fallback));

    return constant;
  }
Example #8
0
  public boolean isVisibleTo(Node currentNode, RubyClass callerClass) {
    switch (visibility) {
      case PUBLIC:
        return true;

      case PROTECTED:
        for (RubyModule ancestor : callerClass.ancestors()) {
          if (ancestor == declaringModule || ancestor.getMetaClass() == declaringModule) {
            return true;
          }
        }

        return false;

      case PRIVATE:
        // A private method may only be called with an implicit receiver,
        // in which case the visibility must not be checked.
        return false;

      default:
        return false;
    }
  }
Example #9
0
  public static IRubyObject searchConst(
      ThreadContext context,
      StaticScope staticScope,
      MutableCallSite site,
      String constName,
      boolean noPrivateConsts)
      throws Throwable {

    // Lexical lookup
    Ruby runtime = context.getRuntime();
    RubyModule object = runtime.getObject();
    IRubyObject constant =
        (staticScope == null)
            ? object.getConstant(constName)
            : staticScope.getConstantInner(constName);

    // Inheritance lookup
    RubyModule module = null;
    if (constant == null) {
      // SSS FIXME: Is this null check case correct?
      module = staticScope == null ? object : staticScope.getModule();
      constant =
          noPrivateConsts
              ? module.getConstantFromNoConstMissing(constName, false)
              : module.getConstantNoConstMissing(constName);
    }

    // Call const_missing or cache
    if (constant == null) {
      return module.callMethod(context, "const_missing", context.runtime.fastNewSymbol(constName));
    }

    SwitchPoint switchPoint = (SwitchPoint) runtime.getConstantInvalidator(constName).getData();

    // bind constant until invalidated
    MethodHandle target = Binder.from(site.type()).drop(0, 2).constant(constant);
    MethodHandle fallback =
        Binder.from(site.type())
            .append(site, constName)
            .append(noPrivateConsts)
            .invokeStatic(LOOKUP, Bootstrap.class, "searchConst");

    site.setTarget(switchPoint.guardWithTest(target, fallback));

    return constant;
  }
Example #10
0
  /** Create the Zlib module and add it to the Ruby runtime. */
  public static RubyModule createZlibModule(Ruby runtime) {
    RubyModule result = runtime.defineModule("Zlib");

    RubyClass gzfile =
        result.defineClassUnder("GzipFile", runtime.getObject(), RubyGzipFile.GZIPFILE_ALLOCATOR);
    gzfile.defineAnnotatedMethods(RubyGzipFile.class);

    RubyClass gzreader =
        result.defineClassUnder("GzipReader", gzfile, RubyGzipReader.GZIPREADER_ALLOCATOR);
    gzreader.includeModule(runtime.getEnumerable());
    gzreader.defineAnnotatedMethods(RubyGzipReader.class);

    RubyClass standardError = runtime.getStandardError();
    RubyClass zlibError =
        result.defineClassUnder("Error", standardError, standardError.getAllocator());
    gzreader.defineClassUnder("Error", zlibError, zlibError.getAllocator());

    RubyClass gzwriter =
        result.defineClassUnder("GzipWriter", gzfile, RubyGzipWriter.GZIPWRITER_ALLOCATOR);
    gzwriter.defineAnnotatedMethods(RubyGzipWriter.class);

    result.defineConstant("ZLIB_VERSION", runtime.newString("1.2.1"));
    result.defineConstant("VERSION", runtime.newString("0.6.0"));

    result.defineConstant("BINARY", runtime.newFixnum(0));
    result.defineConstant("ASCII", runtime.newFixnum(1));
    result.defineConstant("UNKNOWN", runtime.newFixnum(2));

    result.defineConstant("DEF_MEM_LEVEL", runtime.newFixnum(8));
    result.defineConstant("MAX_MEM_LEVEL", runtime.newFixnum(9));

    result.defineConstant("OS_UNIX", runtime.newFixnum(3));
    result.defineConstant("OS_UNKNOWN", runtime.newFixnum(255));
    result.defineConstant("OS_CODE", runtime.newFixnum(11));
    result.defineConstant("OS_ZSYSTEM", runtime.newFixnum(8));
    result.defineConstant("OS_VMCMS", runtime.newFixnum(4));
    result.defineConstant("OS_VMS", runtime.newFixnum(2));
    result.defineConstant("OS_RISCOS", runtime.newFixnum(13));
    result.defineConstant("OS_MACOS", runtime.newFixnum(7));
    result.defineConstant("OS_OS2", runtime.newFixnum(6));
    result.defineConstant("OS_AMIGA", runtime.newFixnum(1));
    result.defineConstant("OS_QDOS", runtime.newFixnum(12));
    result.defineConstant("OS_WIN32", runtime.newFixnum(11));
    result.defineConstant("OS_ATARI", runtime.newFixnum(5));
    result.defineConstant("OS_MSDOS", runtime.newFixnum(0));
    result.defineConstant("OS_CPM", runtime.newFixnum(9));
    result.defineConstant("OS_TOPS20", runtime.newFixnum(10));

    result.defineConstant("DEFAULT_STRATEGY", runtime.newFixnum(0));
    result.defineConstant("FILTERED", runtime.newFixnum(1));
    result.defineConstant("HUFFMAN_ONLY", runtime.newFixnum(2));

    result.defineConstant("NO_FLUSH", runtime.newFixnum(0));
    result.defineConstant("SYNC_FLUSH", runtime.newFixnum(2));
    result.defineConstant("FULL_FLUSH", runtime.newFixnum(3));
    result.defineConstant("FINISH", runtime.newFixnum(4));

    result.defineConstant("NO_COMPRESSION", runtime.newFixnum(0));
    result.defineConstant("BEST_SPEED", runtime.newFixnum(1));
    result.defineConstant("DEFAULT_COMPRESSION", runtime.newFixnum(-1));
    result.defineConstant("BEST_COMPRESSION", runtime.newFixnum(9));

    result.defineConstant("MAX_WBITS", runtime.newFixnum(15));

    result.defineAnnotatedMethods(RubyZlib.class);

    result.defineClassUnder("StreamEnd", zlibError, zlibError.getAllocator());
    result.defineClassUnder("StreamError", zlibError, zlibError.getAllocator());
    result.defineClassUnder("BufError", zlibError, zlibError.getAllocator());
    result.defineClassUnder("NeedDict", zlibError, zlibError.getAllocator());
    result.defineClassUnder("MemError", zlibError, zlibError.getAllocator());
    result.defineClassUnder("VersionError", zlibError, zlibError.getAllocator());
    result.defineClassUnder("DataError", zlibError, zlibError.getAllocator());

    RubyClass gzError = gzfile.defineClassUnder("Error", zlibError, zlibError.getAllocator());
    gzfile.defineClassUnder("CRCError", gzError, gzError.getAllocator());
    gzfile.defineClassUnder("NoFooter", gzError, gzError.getAllocator());
    gzfile.defineClassUnder("LengthError", gzError, gzError.getAllocator());

    // ZStream actually *isn't* allocatable
    RubyClass zstream =
        result.defineClassUnder(
            "ZStream", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    zstream.defineAnnotatedMethods(ZStream.class);
    zstream.undefineMethod("new");

    RubyClass infl = result.defineClassUnder("Inflate", zstream, Inflate.INFLATE_ALLOCATOR);
    infl.defineAnnotatedMethods(Inflate.class);

    RubyClass defl = result.defineClassUnder("Deflate", zstream, Deflate.DEFLATE_ALLOCATOR);
    defl.defineAnnotatedMethods(Deflate.class);

    runtime
        .getKernel()
        .callMethod(runtime.getCurrentContext(), "require", runtime.newString("stringio"));

    return result;
  }
Example #11
0
 private void receivedAnException(ThreadContext context, IRubyObject exception) {
   RubyModule kernelModule = getRuntime().getKernel();
   debug(this, "before propagating exception");
   kernelModule.callMethod(context, "raise", exception);
 }
Example #12
0
  public static void initMethods(RubyModule klass) {
    klass
        .getSingletonClass()
        .defineMethod(
            "dosync",
            new RubyNoOrOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                try {
                  getInstance().addQueueCommand(new SyncCommand(SyncThread.scSyncAll, true));

                } catch (Exception e) {
                  LOG.ERROR("dosync failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
                return getInstance().getRetValue();
              }

              protected RubyValue run(RubyValue receiver, RubyValue arg, RubyBlock block) {
                try {
                  String str = arg.asString();
                  boolean show = arg.equals(RubyConstant.QTRUE) || "true".equalsIgnoreCase(str);
                  getInstance().addQueueCommand(new SyncCommand(SyncThread.scSyncAll, show));
                } catch (Exception e) {
                  LOG.ERROR("dosync failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
                return getInstance().getRetValue();
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "dosync_source",
            new RubyOneOrTwoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg, RubyBlock block) {
                try {
                  int nSrcID = 0;
                  String strName = "";
                  if (arg instanceof RubyFixnum) nSrcID = arg.toInt();
                  else strName = arg.toStr();

                  getInstance()
                      .addQueueCommand(
                          new SyncCommand(SyncThread.scSyncOne, strName, nSrcID, true));
                } catch (Exception e) {
                  LOG.ERROR("dosync_source failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
                return getInstance().getRetValue();
              }

              protected RubyValue run(
                  RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block) {
                try {
                  String str = arg1.asString();
                  boolean show = arg1.equals(RubyConstant.QTRUE) || "true".equalsIgnoreCase(str);

                  int nSrcID = 0;
                  String strName = "";
                  if (arg0 instanceof RubyFixnum) nSrcID = arg0.toInt();
                  else strName = arg0.toStr();

                  getInstance()
                      .addQueueCommand(
                          new SyncCommand(SyncThread.scSyncOne, strName, nSrcID, show));
                } catch (Exception e) {
                  LOG.ERROR("dosync_source failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
                return getInstance().getRetValue();
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "dosearch",
            new RubyVarArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyArray args, RubyBlock block) {
                if (args.size() != 7)
                  throw new RubyException(
                      RubyRuntime.ArgumentErrorClass,
                      "in SyncEngine.dosearch_source: wrong number of arguments ( "
                          + args.size()
                          + " for "
                          + 7
                          + " )");

                try {
                  Vector arSources = RhoRuby.makeVectorStringFromArray(args.get(0));

                  String from = args.get(1).toStr();
                  String params = args.get(2).toStr();

                  String str = args.get(3).asString();
                  int nProgressStep = args.get(4).toInt();
                  String callback = args.get(5) != RubyConstant.QNIL ? args.get(5).toStr() : "";
                  String callback_params =
                      args.get(6) != RubyConstant.QNIL ? args.get(6).toStr() : "";

                  boolean bSearchSyncChanges =
                      args.get(3).equals(RubyConstant.QTRUE) || "true".equalsIgnoreCase(str);
                  stopSync();

                  if (callback != null && callback.length() > 0)
                    getSyncEngine().getNotify().setSearchNotification(callback, callback_params);

                  getInstance()
                      .addQueueCommand(
                          new SyncSearchCommand(
                              from, params, arSources, bSearchSyncChanges, nProgressStep));
                } catch (Exception e) {
                  LOG.ERROR("SyncEngine.login", e);
                  RhoRuby.raise_RhoError(RhoAppAdapter.ERR_RUNTIME);
                }

                return getInstance().getRetValue();
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "stop_sync",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                try {
                  stopSync();
                } catch (Exception e) {
                  LOG.ERROR("stop_sync failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "login",
            new RubyVarArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyArray args, RubyBlock block) {
                if (args.size() != 3)
                  throw new RubyException(
                      RubyRuntime.ArgumentErrorClass,
                      "in SyncEngine.login: wrong number of arguments ( "
                          + args.size()
                          + " for "
                          + 3
                          + " )");

                try {
                  String name = args.get(0).toStr();
                  String password = args.get(1).toStr();
                  String callback = args.get(2).toStr();

                  stopSync();

                  getInstance()
                      .addQueueCommand(
                          new SyncLoginCommand(
                              name,
                              password,
                              callback,
                              new SyncNotify.SyncNotification(callback, "", false)));
                } catch (Exception e) {
                  LOG.ERROR("SyncEngine.login", e);
                  RhoRuby.raise_RhoError(RhoAppAdapter.ERR_RUNTIME);
                }

                return getInstance().getRetValue();
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "logged_in",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                DBAdapter db = DBAdapter.getUserDB();

                try {
                  return getSyncEngine().isLoggedIn()
                      ? ObjectFactory.createInteger(1)
                      : ObjectFactory.createInteger(0);
                } catch (Exception e) {
                  LOG.ERROR("logged_in failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "logout",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                DBAdapter db = DBAdapter.getUserDB();

                try {
                  stopSync();
                  getSyncEngine().stopSyncByUser();
                  getSyncEngine().logout();
                } catch (Exception e) {
                  LOG.ERROR("logout failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_notification",
            new RubyVarArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyArray args, RubyBlock block) {

                try {
                  int source_id = args.get(0).toInt();
                  String url = args.get(1).toStr();
                  String params = args.get(2).toStr();
                  getSyncEngine()
                      .getNotify()
                      .setSyncNotification(
                          source_id,
                          new SyncNotify.SyncNotification(
                              url, params != null ? params : "", source_id != -1));
                } catch (Exception e) {
                  LOG.ERROR("set_notification failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
                return RubyConstant.QNIL;
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "clear_notification",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  int source_id = arg1.toInt();
                  getSyncEngine().getNotify().clearSyncNotification(source_id);
                } catch (Exception e) {
                  LOG.ERROR("clear_notification failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_pollinterval",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  int nOldInterval = getInstance().getPollInterval();
                  int nInterval = arg1.toInt();
                  getInstance().setPollInterval(nInterval);

                  return ObjectFactory.createInteger(nOldInterval);
                } catch (Exception e) {
                  LOG.ERROR("set_pollinterval failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "get_pollinterval",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                try {
                  int nOldInterval = getInstance().getPollInterval();
                  return ObjectFactory.createInteger(nOldInterval);
                } catch (Exception e) {
                  LOG.ERROR("set_pollinterval failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_syncserver",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  String syncserver = arg1.toStr();

                  stopSync();
                  getSyncEngine().setSyncServer(syncserver);

                  if (syncserver != null && syncserver.length() > 0) {
                    SyncThread.getInstance().start(SyncThread.epLow);
                    if (ClientRegister.getInstance() != null)
                      ClientRegister.getInstance().startUp();
                  } else {
                    // DO NOT STOP thread. because they cannot be restarted
                    // SyncThread.getInstance().stop(SYNC_WAIT_BEFOREKILL_SECONDS);
                    // if ( ClientRegister.getInstance() != null )
                    //	ClientRegister.getInstance().stop(SYNC_WAIT_BEFOREKILL_SECONDS);
                  }

                } catch (Exception e) {
                  LOG.ERROR("set_syncserver failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "get_src_attrs",
            new RubyTwoArgMethod() {
              protected RubyValue run(
                  RubyValue receiver, RubyValue arg0, RubyValue arg1, RubyBlock block) {
                try {
                  // String strPartition = arg0.toStr();
                  // int nSrcID = arg1.toInt();
                  // return DBAdapter.getDB(strPartition).getAttrMgr().getAttrsBySrc(nSrcID);
                  return RubyConstant.QNIL;
                } catch (Exception e) {
                  LOG.ERROR("get_src_attrs failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "is_blob_attr",
            new RubyVarArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyArray args, RubyBlock block) {
                try {
                  String strPartition = args.get(0).toStr();
                  Integer nSrcID = new Integer(args.get(1).toInt());
                  String strAttrName = args.get(2).toStr();
                  boolean bExists =
                      DBAdapter.getDB(strPartition).getAttrMgr().isBlobAttr(nSrcID, strAttrName);
                  return ObjectFactory.createBoolean(bExists);
                } catch (Exception e) {
                  LOG.ERROR("get_src_attrs failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_objectnotify_url",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  String url = arg1.toStr();
                  SyncNotify.setObjectNotifyUrl(url);
                } catch (Exception e) {
                  LOG.ERROR("set_objectnotify_url failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "add_objectnotify",
            new RubyTwoArgMethod() {
              protected RubyValue run(
                  RubyValue receiver, RubyValue arg1, RubyValue arg2, RubyBlock block) {
                try {
                  Integer nSrcID = new Integer(arg1.toInt());
                  String strObject = arg2.toStr();

                  getSyncEngine().getNotify().addObjectNotify(nSrcID, strObject);
                } catch (Exception e) {
                  LOG.ERROR("add_objectnotify failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "clean_objectnotify",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                try {
                  getSyncEngine().getNotify().cleanObjectNotifications();
                } catch (Exception e) {
                  LOG.ERROR("clean_objectnotify failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "get_lastsync_objectcount",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  Integer nSrcID = new Integer(arg1.toInt());
                  int nCount = getSyncEngine().getNotify().getLastSyncObjectCount(nSrcID);

                  return ObjectFactory.createInteger(nCount);
                } catch (Exception e) {
                  LOG.ERROR("get_lastsync_objectcount failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "get_pagesize",
            new RubyNoArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyBlock block) {
                try {
                  return ObjectFactory.createInteger(getSyncEngine().getSyncPageSize());
                } catch (Exception e) {
                  LOG.ERROR("get_pagesize failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_pagesize",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  getSyncEngine().setSyncPageSize(arg1.toInt());
                } catch (Exception e) {
                  LOG.ERROR("set_pagesize failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_threaded_mode",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  boolean bThreadMode = arg1 == RubyConstant.QTRUE;
                  getInstance().setNonThreadedMode(!bThreadMode);
                  getSyncEngine().setNonThreadedMode(!bThreadMode);
                } catch (Exception e) {
                  LOG.ERROR("set_threaded_mode failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "enable_status_popup",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  boolean bEnable = arg1 == RubyConstant.QTRUE;
                  getSyncEngine().getNotify().enableStatusPopup(bEnable);
                } catch (Exception e) {
                  LOG.ERROR("enable_status_popup failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });

    klass
        .getSingletonClass()
        .defineMethod(
            "set_source_property",
            new RubyVarArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyArray args, RubyBlock block) {
                try {
                  Integer nSrcID = new Integer(args.get(0).toInt());
                  String strPropName = args.get(1).toStr();
                  String strPropValue = args.get(2).toStr();

                  SyncEngine.getSourceOptions().setProperty(nSrcID, strPropName, strPropValue);

                  return RubyConstant.QNIL;
                } catch (Exception e) {
                  LOG.ERROR("set_source_property failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }
              }
            });
    klass
        .getSingletonClass()
        .defineMethod(
            "set_ssl_verify_peer",
            new RubyOneArgMethod() {
              protected RubyValue run(RubyValue receiver, RubyValue arg1, RubyBlock block) {
                try {
                  boolean bVerify = arg1 == RubyConstant.QTRUE;
                  getSyncEngine().getNet().sslVerifyPeer(bVerify);
                } catch (Exception e) {
                  LOG.ERROR("set_ssl_verify_peer failed", e);
                  throw (e instanceof RubyException
                      ? (RubyException) e
                      : new RubyException(e.getMessage()));
                }

                return RubyConstant.QNIL;
              }
            });
  }