/// <summary> /// Adds an explicit physical message handler to the dispatcher. /// </summary> /// <param name="callback">The handler callback.</param> /// <param name="msgType">The message type to be associated with the handler.</param> /// <param name="sessionInfo"> /// The session related information to be related to this handler (or <c>null</c>). /// </param> /// <remarks> /// <note> /// Methods registered as handlers via this method will have to declare /// their message parameter as the base Msg class so that the compiler can /// create MsgHandlerDelegate instances. The message parameter can then be /// cast to the proper message type within the handler method. /// </note> /// </remarks> public void AddPhysical(MsgHandlerDelegate callback, System.Type msgType, SessionHandlerInfo sessionInfo) { MethodInfo method; MsgHandler handler; method = callback.Method; handler = new MsgHandler(callback.Target, method, msgType, null, sessionInfo); using (TimedLock.Lock(syncLock)) { if (physHandlers.ContainsKey(msgType)) { throw new MsgException("Multiple physical handlers defined for message type [{0}].", msgType); } physHandlers.Add(msgType, handler); } }
/// <summary> /// Adds an explicit logical endpoint message handler to the dispatcher. /// </summary> /// <param name="callback">The handler callback.</param> /// <param name="logicalEP">The logical endpoint.</param> /// <param name="msgType">The message type to be associated with the handler.</param> /// <param name="defHandler"><c>true</c> if this is the default handler for the endpoint.</param> /// <param name="sessionInfo"> /// The session related information to be related to this handler (or <c>null</c>). /// </param> /// <param name="suppressAdvertise"><c>true</c> if the advertise messages should be suppressed for this endpoint.</param> /// <remarks> /// <para> /// Pass suppressAdvertise=<c>true</c> if the dispatcher and associated router to suppress /// the transmission of advertise messages to the other routers on the network. /// This is useful when multiple logical handlers are being added. Once the handlers /// have been added, <see cref="LogicalAdvertise"/> can be called to force the /// advertise. /// </para> /// <note> /// Methods registered as handlers via this method will have to declare /// their message parameter as the base <see cref="Msg" /> class so that the compiler can /// create <see cref="MsgHandlerDelegate" /> instances. The message parameter can then be /// cast to the proper message type within the handler method. /// </note> /// </remarks> public void AddLogical(MsgHandlerDelegate callback, MsgEP logicalEP, System.Type msgType, bool defHandler, SessionHandlerInfo sessionInfo, bool suppressAdvertise) { string msgTypeName; string key; MethodInfo method; MsgHandler handler; method = callback.Method; msgTypeName = msgType.FullName; key = defHandler ? DefaultHandler : msgTypeName; handler = new MsgHandler(callback.Target, method, msgType, null, sessionInfo); using (TimedLock.Lock(syncLock)) { if (!logicalRoutes.Add(new LogicalRoute(logicalEP, key, new MsgHandler(callback.Target, method, msgType, null, sessionInfo)), key)) { if (defHandler) { throw new MsgException("A default logical handler is already defined for [{0}].", logicalEP); } else { throw new MsgException("A logical message handler is alreay defined for endpoint [{0}] and message type [{1}].", logicalEP, msgType); } } if (!suppressAdvertise) { logicalEndpointSetID = Helper.NewGuid(); } } if (!suppressAdvertise && router != null) { router.OnLogicalEndpointSetChange(logicalEndpointSetID); } }
/// <summary> /// Adds a, explicit logical endpoint message handler to the dispatcher. /// </summary> /// <param name="callback">The handler callback.</param> /// <param name="logicalEP">The logical endpoint.</param> /// <param name="msgType">The message type to be associated with the handler.</param> /// <param name="defHandler"><c>true</c> if this is the default handler for the endpoint.</param> /// <param name="sessionInfo"> /// The session related information to be related to this handler (or <c>null</c>). /// </param> /// <remarks> /// <note> /// Methods registered as handlers via this method will have to declare /// their message parameter as the base Msg class so that the compiler can /// create MsgHandlerDelegate instances. The message parameter can then be /// cast to the proper message type within the handler method. /// </note> /// </remarks> public void AddLogical(MsgHandlerDelegate callback, MsgEP logicalEP, System.Type msgType, bool defHandler, SessionHandlerInfo sessionInfo) { AddLogical(callback, logicalEP, msgType, defHandler, sessionInfo, false); }