Skip to content
Permalink
Browse files

Merge pull request #2069 from telstra/restore-correlation-id-in-disco…

…very-packet-events

Restore correlation id in discovery packet events
  • Loading branch information...
sergii-iakovenko committed Mar 14, 2019
2 parents 7048b2e + 54c986b commit 56488cc9afb5127831e189abc56b3d7eed4ae57e
@@ -0,0 +1,52 @@
/* Copyright 2019 Telstra Open Source
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openkilda.floodlight.command;

import org.openkilda.floodlight.utils.CorrelationContext;
import org.openkilda.floodlight.utils.CorrelationContext.CorrelationContextClosable;

/**
* Wrap {@link Command} execution. Main goal is to setup/clean up environment.
*
* <p>One of such setup tasks - is to push correlation-id into MDC.
*/
public class CommandWrapper extends Command {
private final Command target;

public CommandWrapper(Command target) {
super(target.getContext());
this.target = target;
}

@Override
public Command call() throws Exception {
Command successor;
try (CorrelationContextClosable closable = CorrelationContext.create(getContext().getCorrelationId())) {
successor = target.call();
}
return successor;
}

@Override
public Command exceptional(Throwable e) {
return target.exceptional(e);
}

@Override
public boolean isOneShot() {
return target.isOneShot();
}
}
@@ -19,6 +19,7 @@
import org.openkilda.floodlight.KildaCoreConfig;
import org.openkilda.floodlight.command.Command;
import org.openkilda.floodlight.command.CommandContext;
import org.openkilda.floodlight.command.CommandWrapper;
import org.openkilda.floodlight.command.PendingCommandSubmitter;
import org.openkilda.floodlight.utils.CommandContextFactory;

@@ -99,6 +100,7 @@ public void process(List<Command> commands) {
* Execute command without intermediate completion check.
*/
public void processLazy(Command command) {
command = wrapCommand(command);
if (command.isOneShot()) {
executeOneShot(command);
} else {
@@ -118,6 +120,10 @@ public synchronized void submitPending(Command initiator, Future<Command> succes

public synchronized void markCompleted(ProcessorTask task) { }

private Command wrapCommand(Command target) {
return new CommandWrapper(target);
}

private void executeOneShot(Command command) {
executor.execute(() -> {
try {

0 comments on commit 56488cc

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.