/// <summary> /// Construct a "set property confirmation" message. /// </summary> /// <param name="messageID"> /// The message id. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructSetPropertyConfirmationMessage(ID messageID) { return(new Message { ID = ID.NewRandom(), Type = MessageType.SetPropertyConfirmation, SetPropertyMessageID = messageID }); }
/// <summary> /// Construct a "get property result" message. /// </summary> /// <param name="messageID"> /// The message id. /// </param> /// <param name="result"> /// The result. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructGetPropertyResultMessage(ID messageID, object result) { return(new Message { ID = ID.NewRandom(), Type = MessageType.GetPropertyResult, GetPropertyMessageID = messageID, GetPropertyResult = this.m_ObjectWithTypeSerializer.Serialize(result) }); }
/// <summary> /// Construct an "invoke result" message. /// </summary> /// <param name="messageID"> /// The message id. /// </param> /// <param name="result"> /// The result. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructInvokeResultMessage(ID messageID, object result) { return(new Message { ID = ID.NewRandom(), Type = MessageType.InvokeResult, InvokeMessageID = messageID, InvokeResult = this.m_ObjectWithTypeSerializer.Serialize(result) }); }
/// <summary> /// Construct a "get property" message. /// </summary> /// <param name="objectID"> /// The object id. /// </param> /// <param name="property"> /// The property. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructGetPropertyMessage(ID objectID, string property) { return(new Message { ID = ID.NewRandom(), Type = MessageType.GetProperty, GetPropertyObjectID = objectID, GetPropertyPropertyName = property }); }
/// <summary> /// Construct a "set property" message. /// </summary> /// <param name="objectID"> /// The object id. /// </param> /// <param name="property"> /// The property. /// </param> /// <param name="value"> /// The value. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructSetPropertyMessage(ID objectID, string property, object value) { return(new Message { ID = ID.NewRandom(), Type = MessageType.SetProperty, SetPropertyObjectID = objectID, SetPropertyPropertyName = property, SetPropertyPropertyValue = this.m_ObjectWithTypeSerializer.Serialize(value) }); }
/// <summary> /// Construct an "invoke" message. /// </summary> /// <param name="objectID"> /// The object id. /// </param> /// <param name="method"> /// The method. /// </param> /// <param name="typeArguments"> /// The type arguments. /// </param> /// <param name="arguments"> /// The arguments. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructInvokeMessage(ID objectID, string method, Type[] typeArguments, object[] arguments) { return(new Message { ID = ID.NewRandom(), Type = MessageType.Invoke, InvokeObjectID = objectID, InvokeMethod = method, InvokeTypeArguments = typeArguments.Select(x => x.AssemblyQualifiedName).ToArray(), InvokeArguments = arguments.Select(x => this.m_ObjectWithTypeSerializer.Serialize(x)).ToArray() }); }
/// <summary> /// Construct a "fetch confirmation" message. /// </summary> /// <param name="key"> /// The key. /// </param> /// <param name="results"> /// The results. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructFetchResultMessage(ID key, SerializedEntry[] results) { if (results == null) { throw new ArgumentNullException("results"); } return(new Message { ID = ID.NewRandom(), Type = MessageType.FetchResult, FetchKey = key, FetchResult = results }); }
/// <summary> /// Called when an object is being constructed. This is instrumented as the first /// operation to occur in the object's constructors so that this contextual information /// can be set up before any properties or other methods are called. /// </summary> /// <param name="obj"> /// The object that is being constructed. /// </param> /// <exception cref="InvalidOperationException"> /// Thrown if the object is being constructed outside of a distributed context. This /// usually means that you are doing "new SomeType", where SomeType is a distributed type /// within code that is not distributed. /// </exception> public static void Construct(object obj) { if (!(obj is ITransparent)) { throw new InvalidOperationException( "A call to Construct can only occur on a post processed, distributed object."); } var transparentObj = (ITransparent)obj; // Check to see if we've already got a NetworkName; if we have // then we're a named distributed instance that doesn't need the // autoid assigned. if (transparentObj.NetworkName != null && transparentObj.Node != null) { return; } // We need to use some sort of thread static variable; when the post-processor // wraps methods, it also needs to update them so that calls to new are adjusted // so the thread static variable gets set to the object's current node. Then we // pull the information out here to reassign it. // If there's no node context in the thread static variable, then that means someone // is new'ing up a distributed object from outside a distributed scope, and they // haven't used the Distributed<> class to create it. if (DpmConstructContext.LocalNodeContext == null) { throw new InvalidOperationException( "Unable to determine current construction context for distributed object. " + "You can only new distributed objects directly from inside other " + "distributed objects. For construction of a distributed object " + "from a local context, use the Distributed<> class."); } var node = DpmConstructContext.LocalNodeContext; // Allocate a randomly generated NetworkName. transparentObj.Node = DpmConstructContext.LocalNodeContext; transparentObj.NetworkName = "autoid-" + ID.NewRandom(); // Store the object in the Dht. node.Store(transparentObj.NetworkName, obj); // Reset the context automatically. DpmConstructContext.LocalNodeContext = null; }
/// <summary> /// Construct a "connection pong" message. /// </summary> /// <returns> /// The <see cref="Message" />. /// </returns> public Message ConstructConnectionPongMessage() { return(new Message { ID = ID.NewRandom(), Type = MessageType.ConnectionPong }); }
/// <summary> /// Construct a "fetch" message. /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="Message"/>. /// </returns> public Message ConstructFetchMessage(ID key) { return(new Message { ID = ID.NewRandom(), Type = MessageType.Fetch, FetchKey = key }); }