[#24705] yaiba (blade clone) 0.0.1 — Hideto ISHIBASHI <hideto-i@...4u.or.jp>

石橋秀仁です。こんにちは。

29 messages 2000/09/03
[#24837] Re: yaiba (blade clone) 0.0.1 — TAKAHASHI Masayoshi <maki@...> 2000/09/06

高橋征義です。遅いフォローですみません。

[#24840] Re: yaiba (blade clone) 0.0.1 — Hideto ISHIBASHI <hideto-i@...4u.or.jp> 2000/09/06

石橋秀仁です。高橋さん、フォローありがとうございます。

[#24852] Re: yaiba (blade clone) 0.0.1 — TAKAHASHI Masayoshi <maki@...> 2000/09/07

高橋征義です。

[#24856] Re: yaiba (blade clone) 0.0.1 — Hideto ISHIBASHI <hideto-i@...4u.or.jp> 2000/09/07

石橋秀仁です。

[#24711] win32 で RDtool — Kazuhiro NISHIYAMA <zn@...>

http://www.geocities.co.jp/SiliconValley-Bay/4076/

95 messages 2000/09/03
[#24713] Re: win32 で RDtool — nobu.nakada@... 2000/09/03

なかだです。

[#24714] Re: win32 で RDtool — Kazuhiro NISHIYAMA <zn@...> 2000/09/03

nobu.nakada@nifty.ne.jp wrote:

[#24716] Re: win32 で RDtool — nobu.nakada@... 2000/09/03

なかだです。

[#24717] Re: win32 で RDtool — Kazuhiro NISHIYAMA <zn@...> 2000/09/03

message "[ruby-list:24715] Re: win32 で RDtool"

[#24728] Re: win32 で RDtool — rubikitch <rubikitch@...> 2000/09/04

From: Kazuhiro NISHIYAMA <zn@mbf.nifty.com>

[#24735] Re: win32 で RDtool — Tokita Kousui <ktokita@...> 2000/09/04

こんにちは、時田です。

[#24757] Re: win32 で RDtool — rubikitch <rubikitch@...> 2000/09/04

From: Tokita Kousui <ktokita@where-i.net>

[#24771] Re: win32 で RDtool — Tokita Kousui <ktokita@...> 2000/09/05

こんにちは、時田です。

[#24772] Re: win32 で RDtool — rubikitch <rubikitch@...> 2000/09/05

From: Tokita Kousui <ktokita@where-i.net>

[#24773] Re: win32 で RDtool — Kazuhiro NISHIYAMA <zn@...> 2000/09/05

rubikitch <rubikitch@ruby-lang.org> wrote:

[#24774] Re: win32 で RDtool — Tokita Kousui <ktokita@...> 2000/09/05

ども、時田です。

[#24779] Re: win32 で RDtool — Kazuhiro NISHIYAMA <zn@...> 2000/09/05

Tokita Kousui <ktokita@where-i.net> wrote:

[#24783] Re: win32 で RDtool — Tokita Kousui <ktokita@...> 2000/09/05

ども、時田です。

[#24814] Re: win32 で RDtool — Toshiro Kuwabara <toshirok@...3.so-net.ne.jp> 2000/09/05

Toshです。

[#24729] Net::IMAP — Shugo Maeda <shugo@...>

前田です。

27 messages 2000/09/04
[#24743] Re: Net::IMAP — sho@... (TADA Tadashi) 2000/09/04

ただただしです。

[#24745] Re: Net::IMAP — Shugo Maeda <shugo@...> 2000/09/04

前田です。

[#24731] win32 Time zone — Kazuhiro Yoshida <moriq.kazuhiro@...>

もりきゅうです。

18 messages 2000/09/04
[#24732] Re: win32 Time zone — matz@... (Yukihiro Matsumoto) 2000/09/04

まつもと ゆきひろです

[#24744] Re: win32 Time zone — Takahiro Kambe <taca@...> 2000/09/04

In message <E13VsUr-0006Cd-00@ev.netlab.zetabits.co.jp>

[#24958] Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...>

有馬です。

47 messages 2000/09/17
[#24959] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/17

小沢です。

[#24961] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/17

有馬です。

[#24963] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/17

小沢です。

[#24964] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/18

有馬です。

[#24981] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/19

有馬です。

[#24984] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/19

小沢です。

[#24990] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/20

有馬です。

[#24992] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/20

小沢です。

[#24994] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/20

有馬です。

[#25000] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/20

小沢です。Win98でテストしてます。

[#25001] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/20

有馬です。

[#25005] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/20

小沢です。

[#25008] Re: Installer test: ruby-1.6.0-preview — ARIMA Yasuhiro <fit0298@...> 2000/09/20

有馬です。

[#25010] Re: Installer test: ruby-1.6.0-preview — Makoto Ozawa <ozawa@...> 2000/09/20

小沢です。

[#24973] How to check all Thread fin ? — Sakae Kobayashi <sakae@...>

小林栄と申します。

27 messages 2000/09/19
[#24974] Re: How to check all Thread fin ? — Shugo Maeda <shugo@...> 2000/09/19

前田です。

[#24982] Re: How to check all Thread fin ? — kjana@... (YANAGAWA Kazuhisa) 2000/09/19

In message <87k8c9m2az.wl@studly.netlab.co.jp>

[#24987] Re: How to check all Thread fin ? — matz@... (Yukihiro Matsumoto) 2000/09/19

まつもと ゆきひろです

[#25015] Re: How to check all Thread fin ? — keiju@... (石塚圭樹) 2000/09/20

けいじゅ@日本ラショナルソフトウェアです.

[#25022] Re: How to check all Thread fin ? — matz@... (Yukihiro Matsumoto) 2000/09/20

まつもと ゆきひろです

[#25013] file separator for Ruby in Windows — TAKAHASHI Masayoshi <maki@...>

高橋征義です。

36 messages 2000/09/20
[#25024] Re: file separator for Ruby in Windows — matz@... (Yukihiro Matsumoto) 2000/09/20

まつもと ゆきひろです

[#25058] Re: file separator for Ruby in Windows — TAKAHASHI Masayoshi <maki@...> 2000/09/21

高橋征義です。

[#25072] Re: file separator for Ruby in Windows — matz@... (Yukihiro Matsumoto) 2000/09/21

まつもと ゆきひろです

[#25089] Re: file separator for Ruby in Windows — 堀川 久 <vzw00011@...> 2000/09/22

こんにちは。

[#25093] Re: file separator for Ruby in Windows — TAKAHASHI Masayoshi <maki@...> 2000/09/22

高橋征義です。

[#25096] Re: file separator for Ruby in Windows — matz@... (Yukihiro Matsumoto) 2000/09/22

まつもと ゆきひろです

[#25147] media watch 2000.08.24 — Noritsugu Nakamura <nnakamur@...>

16 messages 2000/09/24
[#25148] Re: media watch 2000.08.24 — maili31s@... (SugHimsi as SUGIHARA Hiroshi) 2000/09/24

すぎむし。

[#25169] priority & ThreadGroup (Re: [ruby-dev:9438] Re: $SAFE) — Masatoshi SEKI <m_seki@...>

22 messages 2000/09/25
[#25178] Re: priority & ThreadGroup (Re: [ruby-dev:9438] Re: $SAFE) — matz@... (Yukihiro Matsumoto) 2000/09/26

まつもと ゆきひろです

[#25310] synchronization mechanism — Shugo Maeda <shugo@...> 2000/10/04

前田です。

[#25312] Re: synchronization mechanism — m_seki@... 2000/10/04

[#25316] Re: synchronization mechanism — Shugo Maeda <shugo@...> 2000/10/05

前田です。

[ruby-list:24790] Re: yaiba (blade clone) 0.0.1

From: Hideto ISHIBASHI <hideto-i@...4u.or.jp>
Date: 2000-09-05 13:10:12 UTC
List: ruby-list #24790
石橋秀仁です。こんにちは。自己レスです。

yaibaに入っているdoracle.rbは、Webアプリケーションサーバでいうところの
「DBコネクションプーリング機能」をdRubyサービスとして提供しています。
つまり、リモートホスト上でクエリを発行したり、その結果をRubyのArrayなどの
オブジェクトとして返したりできます。

コネクションプーリングの部分は他のソフトでも役に立ちそうなので、
抜き出して添付します。少し書き換えるといろいろと使えると思います。


添付サンプルの使い方:

at foo.hoge.jp
$ ruby doracle.rb
druby://foo.hoge.jp:17640

at bar.hoge.jp
$ ruby clnt.rb druby://foo.hoge.jp:17640
["00-09-05"]

注意)doracle.rbのDB接続が完了する前にclnt.rbを実行すると、
まだfoo.hoge.jpでdRubyサービスが立ち上がっていないので、
connection refusedになったりします。


カスタマイズの仕方:

ご使用の際は、Doracle#studentsのようなメソッドを、
アプリケーションに応じて追加することになります。
そのメソッドはクライアント側で、
  dqueue = DRbObject.new(nil, there)
  doracle = dqueue.pop
  result = doracle.students   # => Array or something
のように呼び出します。

yaibaでは、このWebアプリケーションサーバを、eRubyスクリプトから
呼び出しています。つまり、ネットワーク透過なので、将来的には
Gnutella方式みたいな分散DBにもしてみたいと思ってます :-)


Hideto ISHIBASHI <hideto-i@rr.iij4u.or.jp> wrote:

> yaiba (blade clone) のソースを公開します。
> http://www.rr.iij4u.or.jp/~hideto-i/rb/archive/yaiba-0.0.1.tar.gz

> 基本的にRDBMSと心中することになりました。Oracleで動いてます。
> PostgreSQLでも動かしたいです。PStore版も、たぶん動くと思いますけど。

--
石橋秀仁 hideto-i@rr.iij4u.or.jp
http://www.rr.iij4u.or.jp/~hideto-i/index.html

Attachments (4)

doracle.rb (2.49 KB, text/x-ruby)
# Copyright (c) 2000 Hideto "rubyholic" ISHIBASHI. All Rights Reserved.

require 'thread'
require 'singleton'
require 'oracle'
require 'drb/drb'
require 'drbrefid'


class DoracleQueue
  include DRbUndumped
  include Singleton

  def initialize
    @conf = Config.instance
    @user = @conf['doracle']['user']
    @passwd = @conf['doracle']['passwd']
    @service = @conf['doracle']['service']
    @minsvr = @conf['doracle']['minimum servers']
    @wait = @conf['doracle']['wait']
    @que = Queue.new
    @minsvr.times do @que.push(new_connection) end
    Thread.start { watch_loop }
  end

  def pop
    @que.pop
  end

 private
  def watch_loop
    loop do
      @que.push(new_connection) until @que.length == @minsvr
      sleep @wait
    end
  end

  def new_connection
    Doracle.new(@user, @passwd, @service)
  end
end



class Doracle
  include DRbUndumped

  def initialize(user, passwd, service)
    @conn = ::Oracle.new(user, passwd, service)
  end

  def terminate
    @conn.logoff
  end

=begin  # application specific methods... change as you like

  def students   # sample method
    retval = []
    begin
      cur = @conn.exec('select name from class_master')
      cur.fetch do |row|
        retval.push(row[0])
      end
    rescue OCIError
      p $!
    ensure
      cur.close
    end
    retval
  end

=end  # application specific methods... change as you like

  def exec(sql)
    retval = []
    begin
      cur = @conn.exec(sql)
      cur.fetch do |row|
        retval.push(row[0])
      end
    rescue OCIError
      p $!
    ensure
      cur.close
    end
    retval
  end

end



class Config
  # system-wide configuration like Windows' registories

  include Singleton

  def initialize
    @hash = Hash.new   # { 'conf name' => 'value', 'foo' => 5, ... }
    @mutex = Mutex.new
  end

  def store(key, value)
    @mutex.synchronize do
      @hash.store(key, value)
    end
  end
  alias []= store

  def fetch(key)
    @mutex.synchronize do
      @hash.fetch(key)
    end
  end
  alias [] fetch
end



if __FILE__ == $0
  Thread.abort_on_exception = true

  # config
  eval(File.open('conf.rb').read)
  conf = Config.instance
  uri = conf['doracle']['druby uri']
  tout = conf['doracle']['druby timeout']
  print(uri, "\n")

  # daemon
  pid = fork
  if pid.nil?
    # child process
    $stdout.close
    $stdin.close
    $stderr.close

    queue = DoracleQueue.instance

    DRb.install_id_conv(DRbRefIdConv.new(tout))
    DRb.start_service(uri, queue)

    DRb.thread.join
  end
  # parent process
  exit 0
end
drbrefid.rb (896 Bytes, text/x-ruby)
require 'thread'

class DRbRefIdConv

  def initialize(time_to_live)
    @time_to_live = time_to_live
    @thr_table = {}     # {id => object}
    @obj_table = {}     # {id => killer thread}
    @thr_sync = Mutex.new
    @obj_sync = Mutex.new
  end

  def to_obj(id)
    obj = ObjectSpace._id2ref(id)
    set_killer(id)
    reset_obj(id, obj)
    obj
  end

  def to_id(obj)
    id = obj.id
    set_killer(id)
    reset_obj(id, obj)
    id
  end

  # note: set_killer before reset_obj
  def reset_obj(id, obj)
    @obj_sync.synchronize do
      @obj_table[id] = obj
    end
  end

 private
  def set_killer(id)     # reset killer
    @thr_sync.synchronize do
      thr = @thr_table[id]
      Thread.kill(thr) if thr
      @thr_table[id] = killer(id)
    end
  end

  def killer(id)
    Thread.start do
      sleep(@time_to_live)
      reset_obj(id, nil)  # remove id from table
    end
  end
end
conf.rb (362 Bytes, text/x-ruby)
# configuration file: Ruby script file

parameters = {
  'doracle' => {
    'user' => 'kumo',
    'passwd' => 'kumosuke',
    'service' => 'fire',
    'minimum servers' => 5,
    'wait' => 0.1,
    'druby uri' => 'druby://localhost:17640',
    'druby timeout' => 30,  # second
  },
}

parameters.each_pair do |key, value|
  Config.instance.store(key, value)
end
clnt.rb (258 Bytes, text/x-ruby)
require 'drbrefid'
require 'drb/drb'

there = ARGV.shift
unless there
  $stderr.puts("usage: #{$0} <server_uri>")
  exit 1
end

DRb.start_service
doracle = DRbObject.new(nil, there)
conn = doracle.pop
result = conn.exec('select sysdate from dual')
p result

In This Thread