132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: July 2004: Initial release
|
|
8
|
|
9 author: Kris
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.net.cluster.tina.TaskThread;
|
|
14
|
|
15 private import tango.core.Exception;
|
|
16
|
|
17 private import tango.net.cluster.NetworkRegistry;
|
|
18
|
|
19 private import tango.net.cluster.tina.ClusterThread;
|
|
20
|
|
21 /******************************************************************************
|
|
22
|
|
23 Thread for handling remote-call requests.
|
|
24
|
|
25 ******************************************************************************/
|
|
26
|
|
27 class TaskThread : ClusterThread
|
|
28 {
|
|
29 private NetworkRegistry registry;
|
|
30
|
|
31 /**********************************************************************
|
|
32
|
|
33 Note that the conduit stays open until the client kills it
|
|
34
|
|
35 **********************************************************************/
|
|
36
|
|
37 this (AbstractServer server, IConduit conduit, Cluster cluster)
|
|
38 {
|
|
39 super (server, conduit, cluster);
|
|
40
|
|
41 // clone the registry so that we have our own set of
|
|
42 // message templates to act as hosts. This eliminates
|
|
43 // allocating hosts on the fly
|
|
44 registry = NetworkRegistry.shared.dup;
|
|
45 }
|
|
46
|
|
47 /**********************************************************************
|
|
48
|
|
49 process client requests
|
|
50
|
|
51 **********************************************************************/
|
|
52
|
|
53 void dispatch ()
|
|
54 {
|
|
55 ProtocolWriter.Command cmd;
|
|
56 char[] channel;
|
|
57 char[] element;
|
|
58
|
|
59 // wait for request to arrive
|
|
60 if (reader.getHeader (cmd, channel, element))
|
|
61 {
|
|
62 // convert to a task. Note that we use a private set of
|
|
63 // msg templates, so we don't collide with other threads
|
|
64 auto task = reader.thaw (registry);
|
|
65
|
|
66 if (task is null)
|
|
67 throw new IllegalArgumentException ("Remote-call instance is not executable");
|
|
68
|
|
69 switch (cmd)
|
|
70 {
|
|
71 case ProtocolWriter.Command.Call:
|
|
72 logger.trace (sprint ("{} executing remote call '{}'", client, task.toString));
|
|
73 task.execute;
|
|
74
|
|
75 writer.put (ProtocolWriter.Command.OK, channel, element, task);
|
|
76 break;
|
|
77
|
|
78 default:
|
|
79 throw new IllegalArgumentException ("invalid command");
|
|
80 }
|
|
81 }
|
|
82 }
|
|
83 }
|
|
84
|