org.jruby.Ruby.getThreadService()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(168)

本文整理了Java中org.jruby.Ruby.getThreadService方法的一些代码示例,展示了Ruby.getThreadService的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getThreadService方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getThreadService

Ruby.getThreadService介绍

暂无

代码示例

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. public String dumpThreads(Gather gather) {
  2. Ruby ruby = this.ruby.get();
  3. RubyThread[] thrs = ruby.getThreadService().getActiveRubyThreads();
  4. StringWriter sw = new StringWriter();
  5. PrintWriter pw = new PrintWriter(sw);
  6. pw.println("All threads known to Ruby instance " + ruby.hashCode());
  7. pw.println();
  8. for (RubyThread th : thrs) {
  9. dumpThread(ruby, th, gather, pw);
  10. }
  11. return sw.toString();
  12. }

代码示例来源:origin: org.jruby/jruby-core

  1. public static RubyThread adopt(IRubyObject recv, Thread t) {
  2. final Ruby runtime = recv.getRuntime();
  3. return adoptThread(runtime, runtime.getThreadService(), (RubyClass) recv, t);
  4. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. public void run() {
  2. nativeThread = Thread.currentThread();
  3. try {
  4. runnable.run();
  5. } finally {
  6. rubyThread.getRuntime().getThreadService().dissociateThread(future);
  7. nativeThread = null;
  8. }
  9. }
  10. });

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(meta = true)
  2. public static IRubyObject exit(IRubyObject receiver, Block block) {
  3. RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread();
  4. synchronized (rubyThread) {
  5. rubyThread.status.set(Status.ABORTING);
  6. // FIXME: This was not checking for non-null before, but maybe it should
  7. rubyThread.mail.set(null);
  8. receiver.getRuntime().getThreadService().setCritical(false);
  9. throw new ThreadKill();
  10. }
  11. }

代码示例来源:origin: com.squareup.rack/rack-servlet

  1. /**
  2. * Creates a byte array Iterator backed by the given Ruby Enumerable.
  3. *
  4. * @param body the backing Enumerable.
  5. */
  6. public JRubyRackBodyIterator(IRubyObject body) {
  7. this.body = body;
  8. this.threadContext = body.getRuntime().getThreadService().getCurrentContext();
  9. this.enumerator = (RubyEnumerator) body.callMethod(threadContext, "to_enum");
  10. }

代码示例来源:origin: org.jruby/jruby-complete

  1. @JRubyMethod(meta = true)
  2. public static RubyArray list(IRubyObject recv) {
  3. Ruby runtime = recv.getRuntime();
  4. RubyThread[] activeThreads = runtime.getThreadService().getActiveRubyThreads();
  5. return RubyArray.newArrayMayCopy(runtime, activeThreads);
  6. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "critical=", required = 1, meta = true, compat = CompatVersion.RUBY1_8)
  2. public static IRubyObject critical_set(IRubyObject receiver, IRubyObject value) {
  3. receiver.getRuntime().getThreadService().setCritical(value.isTrue());
  4. return value;
  5. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. private static RubyThread adoptThread(final IRubyObject recv, Thread t, Block block) {
  2. final Ruby runtime = recv.getRuntime();
  3. final RubyThread rubyThread = new RubyThread(runtime, (RubyClass) recv);
  4. rubyThread.threadImpl = new NativeThread(rubyThread, t);
  5. ThreadContext context = runtime.getThreadService().registerNewThread(rubyThread);
  6. runtime.getThreadService().associateThread(t, rubyThread);
  7. context.preAdoptThread();
  8. // set to default thread group
  9. runtime.getDefaultThreadGroup().addDirectly(rubyThread);
  10. return rubyThread;
  11. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "critical=", required = 1, meta = true, compat = CompatVersion.RUBY1_8)
  2. public static IRubyObject critical_set(IRubyObject receiver, IRubyObject value) {
  3. receiver.getRuntime().getThreadService().setCritical(value.isTrue());
  4. return value;
  5. }

代码示例来源:origin: org.jruby/jruby-complete

  1. @JRubyMethod(name = {"kill", "exit", "terminate"})
  2. public IRubyObject kill() {
  3. Ruby runtime = getRuntime();
  4. // need to reexamine this
  5. RubyThread currentThread = runtime.getCurrentContext().getThread();
  6. if (currentThread == runtime.getThreadService().getMainThread()) {
  7. // rb_exit to hard exit process...not quite right for us
  8. }
  9. status.set(Status.ABORTING);
  10. return genericKill(runtime, currentThread);
  11. }

代码示例来源:origin: asciidoctor/asciidoctorj

  1. public void setRubyProperty(String propertyName, IRubyObject arg) {
  2. ThreadContext threadContext = runtime.getThreadService().getCurrentContext();
  3. if (propertyName.startsWith("@")) {
  4. rubyNode.getInstanceVariables().setInstanceVariable(propertyName, arg);
  5. } else {
  6. if (arg == null) {
  7. rubyNode.callMethod(threadContext, propertyName + "=", runtime.getNil());
  8. } else {
  9. rubyNode.callMethod(threadContext, propertyName + "=", arg);
  10. }
  11. }
  12. }

代码示例来源:origin: org.asciidoctor/asciidoctorj

  1. public void setRubyProperty(String propertyName, IRubyObject arg) {
  2. ThreadContext threadContext = runtime.getThreadService().getCurrentContext();
  3. if (propertyName.startsWith("@")) {
  4. rubyNode.getInstanceVariables().setInstanceVariable(propertyName, arg);
  5. } else {
  6. if (arg == null) {
  7. rubyNode.callMethod(threadContext, propertyName + "=", runtime.getNil());
  8. } else {
  9. rubyNode.callMethod(threadContext, propertyName + "=", arg);
  10. }
  11. }
  12. }

代码示例来源:origin: org.jruby/jruby-core

  1. @JRubyMethod(name = {"kill", "exit", "terminate"})
  2. public IRubyObject kill() {
  3. Ruby runtime = getRuntime();
  4. // need to reexamine this
  5. RubyThread currentThread = runtime.getCurrentContext().getThread();
  6. if (currentThread == runtime.getThreadService().getMainThread()) {
  7. // rb_exit to hard exit process...not quite right for us
  8. }
  9. status.set(Status.ABORTING);
  10. return genericKill(runtime, currentThread);
  11. }

代码示例来源:origin: org.jruby/jruby-complete

  1. @JRubyMethod(meta = true)
  2. public static IRubyObject exit(IRubyObject receiver, Block block) {
  3. RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread();
  4. return rubyThread.kill();
  5. }

代码示例来源:origin: org.jruby/jruby-core

  1. @JRubyMethod(meta = true)
  2. public static IRubyObject exit(IRubyObject receiver, Block block) {
  3. RubyThread rubyThread = receiver.getRuntime().getThreadService().getCurrentContext().getThread();
  4. return rubyThread.kill();
  5. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "critical", meta = true, compat = CompatVersion.RUBY1_8)
  2. public static IRubyObject critical(IRubyObject receiver) {
  3. return receiver.getRuntime().newBoolean(receiver.getRuntime().getThreadService().getCritical());
  4. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "pass", meta = true)
  2. public static IRubyObject pass(IRubyObject recv) {
  3. Ruby runtime = recv.getRuntime();
  4. ThreadService ts = runtime.getThreadService();
  5. boolean critical = ts.getCritical();
  6. ts.setCritical(false);
  7. Thread.yield();
  8. ts.setCritical(critical);
  9. return recv.getRuntime().getNil();
  10. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "list", meta = true)
  2. public static RubyArray list(IRubyObject recv) {
  3. RubyThread[] activeThreads = recv.getRuntime().getThreadService().getActiveRubyThreads();
  4. return recv.getRuntime().newArrayNoCopy(activeThreads);
  5. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = "exclusive", meta = true, compat = CompatVersion.RUBY1_8)
  2. public static IRubyObject exclusive(ThreadContext context, IRubyObject receiver, Block block) {
  3. ThreadService service = context.runtime.getThreadService();
  4. boolean old = service.getCritical();
  5. try {
  6. service.setCritical(true);
  7. return block.yield(receiver.getRuntime().getCurrentContext(), (IRubyObject) null);
  8. } finally {
  9. service.setCritical(old);
  10. }
  11. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. @JRubyMethod(name = {"kill", "exit", "terminate"})
  2. public IRubyObject kill() {
  3. // need to reexamine this
  4. RubyThread currentThread = getRuntime().getCurrentContext().getThread();
  5. // If the killee thread is the same as the killer thread, just die
  6. if (currentThread == this) throwThreadKill();
  7. debug(this, "trying to kill");
  8. currentThread.pollThreadEvents();
  9. getRuntime().getThreadService().deliverEvent(new ThreadService.Event(currentThread, this, ThreadService.Event.Type.KILL));
  10. debug(this, "succeeded with kill");
  11. return this;
  12. }

相关文章

Ruby类方法