root/trunk/lib/jeventmachine.rb

Revision 771, 3.5 kB (checked in by francis, 9 months ago)

Patch by tmm1: fixes bug in the Java implementation:
send_data would not send complete buffers.

  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 Apr 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25
26
27 # This module provides "glue" for the Java version of the EventMachine reactor core.
28 # For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
29 # which is a garden-variety Ruby-extension glue module.
30
31
32 require 'em_reactor'
33
34 module EventMachine
35         # TODO: These event numbers are defined in way too many places.
36         # DRY them up.
37         TimerFired = 100
38         ConnectionData = 101
39         ConnectionUnbound = 102
40         ConnectionAccepted = 103
41         ConnectionCompleted = 104
42         LoopbreakSignalled = 105
43
44         # This thunk class used to be called EM, but that caused conflicts with
45         # the alias "EM" for module EventMachine. (FC, 20Jun08)
46         class JEM < com.rubyeventmachine.EmReactor
47                 def eventCallback a1, a2, a3
48                         s = String.from_java_bytes(a3.array[a3.position...a3.limit])
49                         EventMachine::event_callback a1, a2, s
50                 end
51         end
52         def self.initialize_event_machine
53                 @em = JEM.new
54         end
55         def self.release_machine
56                 @em = nil
57         end
58         def self.add_oneshot_timer interval
59                 @em.installOneshotTimer interval
60         end
61         def self.run_machine
62                 @em.run
63         end
64         def self.stop
65                 @em.stop
66         end
67         def self.start_tcp_server server, port
68                 @em.startTcpServer server, port
69         end
70         def self.stop_tcp_server sig
71                 @em.stopTcpServer sig
72         end
73         def self.start_unix_server filename
74                 # TEMPORARILY unsupported until someone figures out how to do it.
75                 raise "unsupported on this platform"
76         end
77         def self.send_data sig, data, length
78                 @em.sendData sig, data.to_java_bytes
79         end
80         def self.send_datagram sig, data, length, address, port
81                 @em.sendDatagram sig, data, length, address, port
82         end
83         def self.connect_server server, port
84                 @em.connectTcpServer server, port
85         end
86         def self.close_connection sig, after_writing
87                 @em.closeConnection sig, after_writing
88         end
89         def self.set_comm_inactivity_timeout sig, interval
90                 @em.setCommInactivityTimeout sig, interval
91         end
92         def self.start_tls sig
93                 @em.startTls sig
94         end
95         def self.signal_loopbreak
96                 @em.signalLoopbreak
97         end
98         def self.set_timer_quantum q
99                 @em.setTimerQuantum q
100         end
101         def self.epoll
102                 # Epoll is a no-op for Java.
103                 # The latest Java versions run epoll when possible in NIO.
104         end
105         def self.set_rlimit_nofile n_descriptors
106                 # Currently a no-op for Java.
107         end
108         def self.open_udp_socket server, port
109                 @em.openUdpSocket server, port
110         end
111         def self.invoke_popen cmd
112                 # TEMPORARILY unsupported until someone figures out how to do it.
113                 raise "unsupported on this platform"
114         end
115         def self.read_keyboard
116                 # TEMPORARILY unsupported until someone figures out how to do it.
117                 raise "temporarily unsupported on this platform"
118         end
119         def self.set_max_timer_count num
120                 # harmless no-op in Java. There's no built-in timer limit.
121         end
122         def self.library_type
123                 :java
124         end
125
126         class Connection
127                 def associate_callback_target sig
128                         # No-op for the time being
129                 end
130         end
131 end
132
Note: See TracBrowser for help on using the browser.