Re: good name to dispatch events (naming convention)



puzzlecracker <ironsel2000@xxxxxxxxx> writes:
As mentioned before, Connection class handles the requests from
clients, sends them over to some broker, and then dispatches results/
acks to clients .

Thanks for the clarification. If I understand correctly, then, an
instance of the Connection class is instantiated on the server for each
socket connection?

This design violates the Open/Closed Principle. Whenever you
add a new event type, you'll have to modify Connection. You have a
couple of options. The first is to move the behavior from whatever
calls Connection to the events and replace your handler methods with
a generic handler:

private void processRequest(Request reest)
{
request.execute();
}

I dont have a generic type request for my delegates. Events have
different signatures, sometimes comprised of built-in types, that are
read off socket. Perhaps, I am not understanding your suggestion
here.

It was me not having a full understanding of your design. To be
clear, what you're reading off the socket is a stream consisting of the
event type followed by any required parameters?

Another alternative is to use the Chain of Responsibility
pattern to add behavior dynamically while keeping the event classes
relatively simple.

I don't see how the chain of responsibility pattern can be used here,
without making the design more complex and harder to expand. I
basically have one event type per each client service call. Hence
client subscribes to events, calls one of the services, and waits for
results

Assuming I've understood your design correctly, Chain of
Responsibility can be used similarly to how I implemented it here:
http://www.spe.com/Chain_of_Responsibility.html. In your particular
case, the Connection class would be responsible for managing the
socket. When new data arrives, the Connection class reads the event
type and passes it and the socket connection to a chain of handlers.
The handler for that type accepts responsibility and uses the socket
connection to read any additional data required. (Adding a default
error handler to the chain is a good idea.)

Handlers can be added and removed at any time. Either the
Connection class or a shared HandlerChain class can maintain the list.
The interface for the chain consists of three or four methods:
handleEvent, registerHandler, unregisterHandler, and possibly
updateHandler.

The Handler interface, implemented by all event handlers, exposes
only a handleEvent(Event,Socket) method.

This approach makes the system open for extension but closed to
modification, as recommended by the Open-Closed Principle. Each class
has one well-defined responsibility and new functionality can be easily
added without impacting existing, working, tested code.

Will this work in your environment?

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, middleware, SOA)
.



Relevant Pages

  • Problem with a Socket server Opening/Accepting Many sockets and the GC running.
    ... listening on port 11000 and ready to take a new connection. ... I created the Listener socket, ... THen all is well and my clients can connect for about another 3900 ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with a Socket server program opening/accepting many connections and the GC is running.
    ... listening on port 11000 and ready to take a new connection. ... I created the Listener socket, ... connection to be started by my clients. ... I have read all the GC stuff, and socket stuff. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Handling multiple connections
    ... each time select says the socket has more data. ... All data being sent by clients are prepended with a header that indicates ... received and thus delays receiving on the other readable sockets. ... When the client closes the connection, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Socket Programming
    ... > Antony> and the data from two different clients is sent to the appropriate ... above two people regarding the relation between sockets and the TCP ... the server accepts the connection. ... the server gets a new socket bound to a *different port*. ...
    (comp.lang.lisp)
  • Re: Problem with OnReceive method
    ... >I' m developing a multithread application with a socket network ... when a connection arrived it start a new childthread and ... This should have been in the InitInstance handler of the thread! ... You need to read a good book on network programming (e.g., Comer & Stevens, ...
    (microsoft.public.vc.mfc)