Remove debug code for p2p plus formatting

Fixes #10840
This commit is contained in:
Dan Hermann 2019-05-06 16:52:12 -05:00
parent 8a048ccc27
commit d03c0f14a4
5 changed files with 40 additions and 47 deletions

View file

@ -44,10 +44,7 @@ module ::LogStash; module Plugins; module Builtin; module Pipeline; class Input
@queue << event
end
return true
rescue => e
require 'pry'; binding.pry
return true
true
end
def stop

View file

@ -4,16 +4,14 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Class for representing the state of an internal address.
* Represents the state of an internal address.
*/
public class AddressState {
private final String address;
private final Set<PipelineOutput> outputs = ConcurrentHashMap.newKeySet();
private volatile PipelineInput input = null;
AddressState(String address) {
this.address = address;
}
AddressState(String address) {}
/**
* Add the given output and ensure associated input's receivers are updated
@ -38,14 +36,13 @@ public class AddressState {
* @return true if successful, false if another input is listening
*/
public synchronized boolean assignInputIfMissing(PipelineInput newInput) {
// We aren't changing anything
if (input == null) {
input = newInput;
return true;
} else if (input == newInput) {
return true; // We aren't changing anything
} else {
return input == newInput;
}
return false;
}
/**

View file

@ -5,16 +5,13 @@ import org.apache.logging.log4j.Logger;
import org.logstash.RubyUtil;
import org.logstash.ext.JrubyEventExtLibrary;
import java.util.*;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
/**
* This class is essentially the communication bus / central state for the `pipeline` inputs/outputs to talk to each
* other.
*
* This class is threadsafe.
* other. This class is threadsafe.
*/
public class PipelineBus {
final ConcurrentHashMap<String, AddressState> addressStates = new ConcurrentHashMap<>();
@ -24,6 +21,7 @@ public class PipelineBus {
/**
* Sends events from the provided output.
*
* @param sender The output sending the events.
* @param events A collection of JRuby events
* @param ensureDelivery set to true if you want this to retry indefinitely in the event an event send fails
@ -35,7 +33,7 @@ public class PipelineBus {
final ConcurrentHashMap<String, AddressState> addressesToInputs = outputsToAddressStates.get(sender);
addressesToInputs.forEach( (address, addressState) -> {
addressesToInputs.forEach((address, addressState) -> {
final Stream<JrubyEventExtLibrary.RubyEvent> clones = events.stream().map(e -> e.rubyClone(RubyUtil.RUBY));
PipelineInput input = addressState.getInput(); // Save on calls to getInput since it's volatile
@ -61,6 +59,7 @@ public class PipelineBus {
/**
* Should be called by an output on register
*
* @param output output to be registered
* @param addresses collection of addresses on which to register this sender
*/
@ -79,6 +78,7 @@ public class PipelineBus {
/**
* Should be called by an output on close
*
* @param output output that will be unregistered
* @param addresses collection of addresses this sender was registered with
*/
@ -99,13 +99,14 @@ public class PipelineBus {
/**
* Updates the internal state for this output to reflect the fact that there may be a change
* in the inputs receiving events from it.
*
* @param output output to update
*/
private void updateOutputReceivers(final PipelineOutput output) {
outputsToAddressStates.compute(output, (k, value) -> {
ConcurrentHashMap<String, AddressState> outputAddressToInputMapping = value != null ? value : new ConcurrentHashMap<>();
addressStates.forEach( (address, state) -> {
addressStates.forEach((address, state) -> {
if (state.hasOutput(output)) outputAddressToInputMapping.put(address, state);
});
@ -116,6 +117,7 @@ public class PipelineBus {
/**
* Listens to a given address with the provided listener
* Only one listener can listen on an address at a time
*
* @param input Input to register as listener
* @param address Address on which to listen
* @return true if the listener successfully subscribed
@ -143,6 +145,7 @@ public class PipelineBus {
* Stop listening on the given address with the given listener
* Will change behavior depending on whether {@link #isBlockOnUnlisten()} is true or not.
* Will call a blocking method if it is, a non-blocking one if it isn't
*
* @param input Input that should stop listening
* @param address Address on which the input should stop listening
* @throws InterruptedException if interrupted while attempting to stop listening
@ -157,6 +160,7 @@ public class PipelineBus {
/**
* Stop listening on the given address with the given listener
*
* @param input Input that should stop listening
* @param address Address on which to stop listening
* @throws InterruptedException if interrupted while attempting to stop listening
@ -185,7 +189,7 @@ public class PipelineBus {
return state;
});
if (waiting[0] == false) {
if (!waiting[0]) {
break;
} else {
Thread.sleep(100);
@ -195,6 +199,7 @@ public class PipelineBus {
/**
* Unlisten to use during reloads. This lets upstream outputs block while this input is missing
*
* @param input Input that should stop listening
* @param address Address on which to stop listening
*/

View file

@ -6,15 +6,14 @@ import java.util.stream.Stream;
public interface PipelineInput {
/**
* Accepts an event
* It might be rejected if the input is stopping
* Accepts an event. It might be rejected if the input is stopping.
*
* @param events a collection of events
* @return true if the event was successfully received
*/
boolean internalReceive(Stream<JrubyEventExtLibrary.RubyEvent> events);
/**
*
* @return true if the input is running
*/
boolean isRunning();

View file

@ -1,9 +1,4 @@
package org.logstash.plugins.pipeline;
import org.logstash.ext.JrubyEventExtLibrary;
import java.util.Map;
import java.util.function.Function;
public interface PipelineOutput {
}