public ReaderWriter(INode creator, IMessageHub messageHub, IEnumerable <IConfiguration> configMap, IMessageSerializer serializer) { var configurations = configMap.ToDictionary(c => c.Key, c => c); this.serializer = serializer; op = new CurrentOperation { Phase = new ObservableAtomicValue <OperationPhase>(OperationPhase.Idle), Type = new ObservableAtomicValue <OperationType>(OperationType.Idle), Accepted = new ObservableConcurrentDictionary <int, INode>(Enumerable.Empty <KeyValuePair <int, INode> >()), ConfigurationMap = new ObservableConcurrentDictionary <IConfigurationIndex, IConfiguration>(configurations) }; gc = new GarbageCollectionOperation { Phase = new ObservableAtomicValue <OperationPhase>(OperationPhase.Idle) }; this.creator = creator; this.configMap = new ObservableConcurrentDictionary <IConfigurationIndex, IConfiguration>(configurations); this.messageHub = messageHub; value = new ObjectValue { Value = 0 }; tag = new Tag(creator); localPhase = new PhaseNumber(); operationQueue = new BlockingCollection <OperationRequest>(new ConcurrentQueue <OperationRequest>()); eventHandlers = new EventHandlerList(); status = new ObservableAtomicValue <NodeStatus>(NodeStatus.Idle); world = new ObservableConcurrentDictionary <int, INode>(); phaseVector = new ObservableConcurrentDictionary <INode, IPhaseNumber>(); preJoinAck = new ObservableCondition(() => status.Get() == NodeStatus.Active, new[] { status }); preOutSend = new ObservableCondition(() => status.Get() == NodeStatus.Active, new[] { status }); preQueryFix = new ObservableCondition(QueryFixCondition, new IChangeNotifiable[] { status, op.Type, op.Phase, op.Accepted, op.ConfigurationMap }); prePropagationFix = new ObservableCondition(PropagationFixCondition, new IChangeNotifiable[] { status, op.Type, op.Phase, op.Accepted, op.ConfigurationMap }); preReadAck = new ObservableCondition(() => status.Get() == NodeStatus.Active && op.Type.Get() == OperationType.Read && op.Phase.Get() == OperationPhase.Done, new IChangeNotifiable[] { status, op.Type, op.Phase }); preWriteAck = new ObservableCondition(() => status.Get() == NodeStatus.Active && op.Type.Get() == OperationType.Write && op.Phase.Get() == OperationPhase.Done, new IChangeNotifiable[] { status, op.Type, op.Phase }); new Thread(ProcessReadWriteRequests).Start(); new Thread(OutJoinAck).Start(); new Thread(OutSend).Start(); new Thread(IntQueryFix).Start(); new Thread(IntPropagationFix).Start(); new Thread(OutReadAck).Start(); new Thread(OutWriteAck).Start(); var listener = messageHub.Subscribe(creator); listener.Where(m => m.Body.MessageType.ToMessageType() == MessageTypes.JoinRw) .Subscribe(new MessageStreamListener(OnJoinReceived)); listener.Where(m => m.Body.MessageType.ToMessageType() == MessageTypes.Gossip) .Subscribe(new MessageStreamListener(OnGossipReceived)); }
public static void AssertObjectValueSerializedNull(IObjectValue typedValue) { Assert.NotNull(typedValue); Assert.IsFalse(typedValue.IsDeserialized); Assert.NotNull(typedValue.SerializationDataFormat); Assert.IsNull(typedValue.ValueSerialized); Assert.IsNull(typedValue.ObjectTypeName); }
public void Write(IObjectId x, IObjectValue v) { operationQueue.Add(new OperationRequest { OpType = OperationType.Write, Id = x, Value = v }); }
private void OnReadAck(IObjectId objectId, IObjectValue objectValue) { var handler = eventHandlers[ReadAckEvent] as ReadAckEventHandler; if (handler != null) { handler(objectId, objectValue); } }
private void InternalWrite(IObjectId x, IObjectValue v) { if (!IsIdleOrFailed()) { localPhase.Increment(); op.PhaseNumber = localPhase; op.Accepted = new ObservableConcurrentDictionary <int, INode>(); op.Value = v; op.ConfigurationMap = configMap; op.Phase.Set(OperationPhase.Query); op.Type.Set(OperationType.Write); } }
public static void AssertObjectValueDeserialized(IObjectValue typedValue, object value) { var expectedObjectType = value.GetType(); Assert.True(typedValue.IsDeserialized); Assert.AreEqual(ValueTypeFields.Object, typedValue.Type); Assert.AreEqual(value, typedValue.Value); Assert.AreEqual(value, typedValue.GetValue(expectedObjectType)); Assert.AreEqual(expectedObjectType, typedValue.ObjectType); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.GetName method: Assert.AreEqual(expectedObjectType.FullName, typedValue.ObjectTypeName); }
/// <summary> /// query-fix i /// </summary> private void IntQueryFix() { preQueryFix.Waitable.WaitOne(); if (op.Type.Get() == OperationType.Read) { op.Value = value; } else { value = op.Value; tag.Increment(); localPhase.Increment(); } op.Accepted.Set(Enumerable.Empty <KeyValuePair <int, INode> >()); op.ConfigurationMap.Set(configMap); op.Phase.Set(OperationPhase.Propagation); }
/// <summary> /// recv(world; v; t; cm; snder-phase; rcver-phasei)j;i /// </summary> /// <param name="message"></param> private void OnGossipReceived(IMessage message) { if (!IsIdleOrFailed()) { var gossip = serializer.Deserialize <Gossip>(message.Body.Content); status.Set(NodeStatus.Active); MergeWorld(world, gossip.World); if (gossip.Tag.GreaterThan(tag)) { value = gossip.Value; tag = gossip.Tag; } UpdateConfigurationMap(configMap, gossip.Configurations); if (gossip.SenderPhase.Number > phaseVector[message.Envelope.Sender.Node].Number) { phaseVector[message.Envelope.Sender.Node] = gossip.SenderPhase; } var opPhase = op.Phase.Get(); if (opPhase == OperationPhase.Query || opPhase == OperationPhase.Propagation) { if (gossip.ReceiverPhase.Number >= op.PhaseNumber.Number) { ExtendConfigurationMap(op.ConfigurationMap, gossip.Configurations); if (Usable(op.ConfigurationMap)) { op.Accepted[message.Envelope.Sender.Node.Id] = message.Envelope.Sender.Node; } else { localPhase.Increment(); op.Accepted = new ObservableConcurrentDictionary <int, INode>(); op.ConfigurationMap = configMap; } } if (gossip.ReceiverPhase.Number >= gc.PhaseNumber.Number) { gc.Accepted[message.Envelope.Sender.Node.Id] = message.Envelope.Sender.Node; } } } }
public static void AssertObjectValueSerializedJava(IObjectValue typedValue, object value) { Assert.AreEqual(Variables.SerializationDataFormats.Net, typedValue.SerializationDataFormat); try { //TODO // validate this is the base 64 encoded string representation of the serialized value of the java object var valueSerialized = typedValue.ValueSerialized; //byte[] decodedObject = Base64.DecodeBase64(valueSerialized.GetBytes(Encoding.UTF8)); //ObjectInputStream objectInputStream = new ObjectInputStream(new MemoryStream(decodedObject)); //Assert.AreEqual(value, objectInputStream.ReadObject()); } catch (IOException e) { throw; } //catch (ClassNotFoundException e) //{ // throw new Exception(e); //} }
public ObjectVariableBuilderImpl(IObjectValue value) { VariableValue = (ObjectValueImpl)value; }
private void OnReadAck(IObjectId objectId, IObjectValue objectValue) { logger.InfoFormat("Read value: {0}", objectValue.Value); read.Set(); }
public SerializedObjectValueBuilderImpl(IObjectValue value) { VariableValue = (ObjectValueImpl)value; }
public virtual void testTaskExecutionVariables() { string ProcessInstanceId = runtimeService.StartProcessInstanceByKey("oneTaskProcess").Id; string taskId = taskService.CreateTaskQuery().First().Id; IDictionary <string, object> expectedVariables = new Dictionary <string, object>(); Assert.AreEqual(expectedVariables, runtimeService.GetVariables(ProcessInstanceId)); Assert.AreEqual(expectedVariables, taskService.GetVariables(taskId)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocal(ProcessInstanceId)); Assert.AreEqual(expectedVariables, taskService.GetVariablesLocal(taskId)); runtimeService.SetVariable(ProcessInstanceId, "instrument", "trumpet"); expectedVariables = new Dictionary <string, object>(); Assert.AreEqual(expectedVariables, taskService.GetVariablesLocal(taskId)); expectedVariables["instrument"] = "trumpet"; Assert.AreEqual(expectedVariables, runtimeService.GetVariables(ProcessInstanceId)); Assert.AreEqual(expectedVariables, taskService.GetVariables(taskId)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocal(ProcessInstanceId)); taskService.SetVariable(taskId, "player", "gonzo"); expectedVariables = new Dictionary <string, object>(); Assert.AreEqual(expectedVariables, taskService.GetVariablesLocal(taskId)); expectedVariables["player"] = "gonzo"; expectedVariables["instrument"] = "trumpet"; Assert.AreEqual(expectedVariables, runtimeService.GetVariables(ProcessInstanceId)); Assert.AreEqual(expectedVariables, taskService.GetVariables(taskId)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocal(ProcessInstanceId)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocal(ProcessInstanceId, null)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocalTyped(ProcessInstanceId, null, true)); taskService.SetVariableLocal(taskId, "budget", "unlimited"); expectedVariables = new Dictionary <string, object>(); expectedVariables["budget"] = "unlimited"; Assert.AreEqual(expectedVariables, taskService.GetVariablesLocal(taskId)); Assert.AreEqual(expectedVariables, taskService.GetVariablesLocalTyped(taskId, true)); expectedVariables["player"] = "gonzo"; expectedVariables["instrument"] = "trumpet"; Assert.AreEqual(expectedVariables, taskService.GetVariables(taskId)); Assert.AreEqual(expectedVariables, taskService.GetVariablesTyped(taskId, true)); Assert.AreEqual(expectedVariables, taskService.GetVariables(taskId, null)); Assert.AreEqual(expectedVariables, taskService.GetVariablesTyped(taskId, null, true)); expectedVariables = new Dictionary <string, object>(); expectedVariables["player"] = "gonzo"; expectedVariables["instrument"] = "trumpet"; Assert.AreEqual(expectedVariables, runtimeService.GetVariables(ProcessInstanceId)); Assert.AreEqual(expectedVariables, runtimeService.GetVariablesLocal(ProcessInstanceId)); // typed variable API List <string> serializableValue = new List <string>(); serializableValue.Add("1"); serializableValue.Add("2"); //taskService.SetVariable(taskId, "objectVariable", objectValue(serializableValue).Create()); List <string> serializableValueLocal = new List <string>(); serializableValueLocal.Add("3"); serializableValueLocal.Add("4"); //taskService.SetVariableLocal(taskId, "objectVariableLocal", objectValue(serializableValueLocal).Create()); object value = taskService.GetVariable(taskId, "objectVariable"); Assert.AreEqual(serializableValue, value); object valueLocal = taskService.GetVariableLocal(taskId, "objectVariableLocal"); Assert.AreEqual(serializableValueLocal, valueLocal); IObjectValue typedValue = taskService.GetVariableTyped <IObjectValue>(taskId, "objectVariable"); Assert.AreEqual(serializableValue, typedValue.Value); IObjectValue serializedValue = taskService.GetVariableTyped <IObjectValue>(taskId, "objectVariable", false); Assert.IsFalse(serializedValue.IsDeserialized); IObjectValue typedValueLocal = taskService.GetVariableLocalTyped <IObjectValue>(taskId, "objectVariableLocal"); Assert.AreEqual(serializableValueLocal, typedValueLocal.Value); IObjectValue serializedValueLocal = taskService.GetVariableLocalTyped <IObjectValue>(taskId, "objectVariableLocal", false); Assert.IsFalse(serializedValueLocal.IsDeserialized); try { IObjectValue val = taskService.GetVariableTyped <IObjectValue>(taskId, "objectVariable"); Assert.Fail("expected exception"); } catch (System.InvalidCastException) { //happy path } }
private static IObjectValueItem ToDataObjectItem(PropertyInfo prop, object data, IObjectValue parent = null) { if (prop == null) { throw new ArgumentNullException(nameof(prop)); } var value = prop.GetValue(data); //Parents = new[] { parent.Identity }; //Readonly = !prop.CanWrite; //var dataType = prop.GetCustomAttribute<DataTypeAttribute>() // ?? new DataTypeAttribute(DataType.Text); //DataType = dataType.DataType == DataType.Custom // ? dataType.CustomDataType // : dataType.DataType.ToString(); //Default = prop.GetCustomAttribute<DefaultValueAttribute>()?.Value?.ToString(); var display = prop.GetCustomAttribute <DisplayAttribute>(); // todo необходимо добавить логику на каких типах остановиться return(new CompositeValueField(prop.Name, value.ToDataObject(), parent) { Title = display?.Name ?? prop.Name, Description = display?.Description, Prompt = display?.Prompt }); }
public void Write(IObjectId x, IObjectValue v) { readerWriter.Write(x, v); }