public IEnumerator<ITask> CommandCheckTask() {
while (m_ReloadConfig.State < ReloadConfig.RELOAD_State.Exit) {
//lock (m_ReloadConfig.CommandQueue)
{
//TODO: geht nur für GatherCommandsInQueue
if (ReloadConfig.CommandQueuePort.ItemCount > 0 /*&& ReloadConfig.CommandQueuePort.ItemCount == (gatheredSpecifiersQueue.ItemCount + gatheredStoreDatasQueue.ItemCount)*/) {
string s;
//ReloadConfig.CommandQueuePort.Test(out s);
while (ReloadConfig.CommandQueuePort.Test(out s)) {
if (s == null)
continue;
if (s == "PreJoin") {
ReloadConfig.IamClient = false;
if (ReloadConfig.IsBootstrap)
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO, "This is the bootstrap server");
else {
Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask<List<BootstrapServer>>(m_BootstrapServerList, m_transport.PreJoinProdecure));
}
}
else if (s.StartsWith("Store")) {
//Queue or not?
//if (gatheredStoreDatasQueue.ItemCount > 0)
gatheredStoreDatas = (List<StoreKindData>)gatheredStoreDatasQueue;
string resourceName = gatheredStoreDatas[0].Values[0].Value.GetUsageValue.ResourceName;
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_USAGE,
String.Format("Calling Store: {0}", resourceName));
List<StoreKindData> storeKindData = new List<StoreKindData>();
storeKindData.AddRange(gatheredStoreDatas);
m_transport.StoreDone = new Port<ReloadDialog>();
if (storeViaGateway.ContainsKey(gatheredStoreDatas)) { // --joscha
NodeId via = storeViaGateway[gatheredStoreDatas];
storeViaGateway.Remove(gatheredStoreDatas);
Arbiter.Activate(ReloadConfig.DispatcherQueue,
new IterativeTask<string, List<StoreKindData>,
NodeId>(resourceName, storeKindData, via, m_transport.Store));
}
else
Arbiter.Activate(ReloadConfig.DispatcherQueue,
new IterativeTask<string, List<StoreKindData>>(
resourceName, storeKindData, m_transport.Store));
Arbiter.Activate(m_ReloadConfig.DispatcherQueue,
Arbiter.Receive(true, m_transport.StoreDone, dialog => {
if (StoreCompleted != null) StoreCompleted(dialog);
}));
gatheredStoreDatas.Clear();
}
else if (s.StartsWith("Fetch")) {
List<StoredDataSpecifier> specifier; //necessary to pass a valid reference to m_transport.Fetch
//Queue or not?
if (gatheredSpecifiersQueue.ItemCount > 0)
specifier = (List<StoredDataSpecifier>)gatheredSpecifiersQueue;
else
specifier = gatheredSpecifiers;
if (specifier == null) {
break; //TODO:
}
string FetchUrl = specifier[0].ResourceName;
if (FetchUrl.Length > 0) {
ReloadConfig.ConnEstStart = DateTime.Now;
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
String.Format("Calling Fetch: {0}", FetchUrl));
/* Ports used to notify */
m_transport.FetchDone = new Port<List<IUsage>>();
m_transport.AppAttachDone = new Port<IceCandidate>();
List<StoredDataSpecifier> specifiers = new List<StoredDataSpecifier>(); //copy of specifier needed for fetch task
specifiers.AddRange(specifier);
if (fetchViaGateway.ContainsKey(specifier)) { // --joscha
NodeId via = fetchViaGateway[specifier];
fetchViaGateway.Remove(specifier);
Arbiter.Activate(ReloadConfig.DispatcherQueue,
new IterativeTask<string, List<StoredDataSpecifier>, NodeId>(
FetchUrl, specifiers, via, m_transport.Fetch));
}
else
Arbiter.Activate(ReloadConfig.DispatcherQueue,
new IterativeTask<string, List<StoredDataSpecifier>>(
FetchUrl, specifiers, m_transport.Fetch));
}
else
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR,
String.Format("Empty Fetch command!"));
/* Fetch completed notify everybody */
Arbiter.Activate(ReloadConfig.DispatcherQueue,
Arbiter.Receive(true, m_transport.FetchDone,
delegate(List<IUsage> usages) {
if (FetchCompleted != null) FetchCompleted(usages);
gatheredSpecifiers.Clear();
}));
/* Corresponding AppAttach completed, notify everybody */
Arbiter.Activate(ReloadConfig.DispatcherQueue,
Arbiter.Receive(true, m_transport.AppAttachDone, ice => {
if (AppAttachCompleted != null) AppAttachCompleted(ice);
}));
}
else if (s == "Leave") {
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
String.Format("Received \"Leave\" command"));
if (ReloadConfig.IsBootstrap) {
ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_INFO,
String.Format("Bootstrap Server cannot leave"));
}
else {
if (ReloadConfig.IamClient)
{
Arbiter.Activate(ReloadConfig.DispatcherQueue,
new IterativeTask<string, List<StoreKindData>>(ReloadConfig.SipUri,
new List<StoreKindData>(), m_transport.Store));
}
else
{
if (ReloadConfig.DispatcherQueue != null)
Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask<bool>(true, m_transport.HandoverKeys));
}
//ReloadConfig.IamClient = true;
}
// peer looses bootstrap flag, this is important for rejoin
//TKTODO Rejoin of bootstrap server not solved
}
else if (s == "Exit") {
Finish();
}
else if (s == "Maintenance") {
if (!ReloadGlobals.fMaintenance)
Arbiter.Activate(ReloadConfig.DispatcherQueue, new IterativeTask(Maintenance));
ReloadGlobals.fMaintenance = !ReloadGlobals.fMaintenance;
}
else if (s == "Info") {
PrintNodeInfo(m_topology, true);
}
}
//ReloadConfig.CommandQueue.Clear();
}
//ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_KEEPALIVE, "");
if (ReloadConfig.State != RELOAD.ReloadConfig.RELOAD_State.Exit)
{
Port<DateTime> timeoutPort = new Port<DateTime>();
ReloadConfig.DispatcherQueue.EnqueueTimer(new TimeSpan(0, 0, 0, 0, 100 /* ms 100ms default */), timeoutPort);
yield return Arbiter.Receive(false, timeoutPort, x => { });
}
}
}
}