code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public static boolean isReservedVariable( String variableName ){
return ReservedVariables.NOW.equalsIgnoreCase( variableName ) || ReservedVariables.WORKFLOW_INSTANCE_ID.equalsIgnoreCase( variableName );
} | java |
private Tree<Row> findIf( Tree<Row> pointer ){
while( !Type.IF.equals( pointer.getContent().getType() ) ){
pointer = pointer.getPrevious();
}
return pointer;
} | java |
private Tree<Row> findEndIf( Tree<Row> pointer ){
while( !Type.END_IF.equals( pointer.getContent().getType() ) ){
pointer = pointer.getNext();
}
return pointer;
} | java |
private Tree<Row> findNext( Tree<Row> pointer ){
if( pointer.hasNext() ){
// The given tree-node is not the last in its block.
if( Type.END.equals( pointer.getNext().getContent().getType() ) ){
return null;
}
else{
return pointer.ge... | java |
public static Method findMatchingMethod(Class<?> classToInspect, Class<?> returnType, Object... params) {
Method[] methods = classToInspect.getMethods();
Method checkedMethod = null;
for (Method method : methods) {
Type[] parameterTypes = method.getParameterTypes();
// if... | java |
@SuppressWarnings("unchecked")
public static <T> Constructor<T> findMatchingConstructor(Class<T> classToInspect, Object... params) {
Constructor<T> checkedConstructors = null;
for (Constructor<?> constructor : classToInspect.getDeclaredConstructors()) {
Type[] parameterTypes = constructo... | java |
protected <A extends AggregateRoot<?>> A createFromFactory(Class<A> aggregateClass, Object... parameters) {
checkNotNull(aggregateClass);
checkNotNull(parameters);
Factory<A> factory = domainRegistry.getFactory(aggregateClass);
// Find the method in the factory which match the signatur... | java |
static void serialize(final Document doc, final OutputStream os, final String encoding)
throws TransformerFactoryConfigurationError, TransformerException, IOException
{
if (doc == null)
throw new IllegalArgumentException("No document provided.");
if (os == null)
throw new IllegalArgumentE... | java |
@Override
public byte[] toByteArray() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(16);
outputStream.write(commandByte);
outputStream.write(sysexCommandByte);
if (serialize(outputStream)) {
outputStream.write(CommandBytes.END_SYSEX.getCommandByte());... | java |
@Override
protected boolean isValidFragment(String fragmentName) {
Boolean knownFrag = false;
for (Class<?> cls : INNER_CLASSES) {
if ( cls.getName().equals(fragmentName) ){
knownFrag = true;
break;
}
}
return knownFrag;
... | java |
public byte[] toByteArray() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32);
outputStream.write(commandByte);
if (serialize(outputStream)) {
return outputStream.toByteArray();
}
return null;
} | java |
protected void fireEvent(SerialPortEventTypes eventType) {
executor.submit(new Runnable() {
@Override
public void run() {
for (SerialPortEventListener listener : eventListeners) {
listener.serialEvent(new SerialPortEvent(eventType));
}
... | java |
public ArrayList<PinCapability> getPinCapabilities(Integer pin) {
if (pinCapabilities.size() >= pin) {
return pinCapabilities.get(pin);
}
return null;
} | java |
public void addMessageListener(Integer channel, MessageListener<? extends Message> messageListener) {
addListener(channel, messageListener.getMessageType(), messageListener);
} | java |
public void addMessageListener(DigitalChannel channel, MessageListener<? extends Message> messageListener) {
addListener(channel.getIdentifier(), messageListener.getMessageType(), messageListener);
} | java |
public void addMessageListener(Class<? extends Message> messageClass, MessageListener<Message> messageListener) {
addMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener);
} | java |
public void removeMessageListener(Class<? extends Message> messageClass,
MessageListener<Message> messageListener) {
removeMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener);
} | java |
public synchronized Boolean sendMessage(TransmittableMessage message) {
if (!start()) {
log.error("Firmata library is not connected / started! Cannot send message {}",
message.getClass().getSimpleName());
return false;
}
try {
log.debug("T... | java |
public synchronized Boolean sendRaw(byte... rawBytes) {
if (!start()) {
log.error("Firmata library is not connected / started! Cannot send bytes {}",
FirmataHelper.bytesToHexString(rawBytes));
return false;
}
try {
serialPort.getOutputStre... | java |
public synchronized Boolean start() {
if (started) {
return true;
}
createSerialPort();
serialPort.addEventListener(this);
if (!serialPort.connect()) {
log.error("Failed to start Firmata Library. Cannot connect to Serial Port.");
log.error("... | java |
public synchronized Boolean stop() {
if (serialPort != null) {
serialPort.removeEventListener(this);
}
if (!removeSerialPort()) {
log.error("Failed to stop Firmata Library. Cannot close Serial Port.");
log.error("Configuration is {}", configuration);
... | java |
private void createSerialPort() {
Constructor<? extends SerialPort> constructor;
try {
constructor = configuration.getSerialPortAdapterClass().getDeclaredConstructor(
String.class, Integer.class,
SerialPortDataBits.class, SerialPortStopBits.class, Ser... | java |
private Boolean removeSerialPort() {
Boolean ret = true;
if (serialPort != null) {
ret = serialPort.disconnect();
serialPort = null;
}
return ret;
} | java |
private void handleDataAvailable() {
InputStream inputStream = serialPort.getInputStream();
try {
while (inputStream.available() > 0) {
byte inputByte = (byte) inputStream.read();
if (inputByte == -1) {
log.error("Reached end of stream try... | java |
private void routeMessage(Message message) {
Class messageClass = message.getClass();
// Dispatch message to all specific listeners for the message class type
if (messageListenerMap.containsKey(messageClass)) {
dispatchMessage(messageListenerMap.get(messageClass), message);
... | java |
@SuppressWarnings("unchecked")
private void dispatchMessage(ArrayListMultimap<Integer, MessageListener> listenerMap, Message message) {
List<MessageListener> messageListeners;
// If the message is a Channel Message, hit the channel based listeners first.
if (message instanceof ChannelMessag... | java |
public Message handleInputStream(byte commandByte, InputStream inputStream) {
// Firmata command bytes are limited to a 0xF0 mask, or bytes 0xF0-0xFF
// The extra data in the byte is for routing the command to various 'midi channels'
// or in our case Firmata device pins.
byte firmat... | java |
@Override
public void messageReceived(T message) {
if (responseReceived != null) {
if (responseReceived) {
log.warn("Received more than one synchronous message reply!");
}
else {
log.warn("Received response message after timeout was hit!");... | java |
@Override
public Message buildMessage(Byte channelByte, InputStream inputStream) {
byte sysexCommandByte;
try {
sysexCommandByte = (byte) inputStream.read();
} catch (IOException e) {
log.error("Error reading Sysex command byte.");
return null;
}
... | java |
public static String sanitize(String raw) {
return (raw == null || raw.length() == 0) ? raw : HTMLEntityEncode(canonicalize(raw));
} | java |
public static String HTMLEntityEncode(String input) {
String next = scriptPattern.matcher(input).replaceAll("script");
StringBuffer sb = new StringBuffer();
for (int i = 0; i < next.length(); ++i) {
char ch = next.charAt(i);
if (ch == '<') {
sb.appe... | java |
private void checkEnd() {
if (ended && !closed && children == 0) {
closed = true;
connection.doBatchEnd(id, endArgs);
if (endHandler != null) {
endHandler.handle((Void) null);
}
}
} | java |
void start(Handler<ConnectionOutputBatch> startHandler) {
connection.doBatchStart(id, args);
this.startHandler = startHandler;
} | java |
public List<String> getInPorts() {
List<String> ports = new ArrayList<>();
JsonObject jsonPorts = config.getObject("ports");
if (jsonPorts == null) {
return ports;
}
JsonArray jsonInPorts = jsonPorts.getArray("in");
if (jsonInPorts == null) {
return ports;
}
for (Object jsonI... | java |
public List<String> getOutPorts() {
List<String> ports = new ArrayList<>();
JsonObject jsonPorts = config.getObject("ports");
if (jsonPorts == null) {
return ports;
}
JsonArray jsonOutPorts = jsonPorts.getArray("out");
if (jsonOutPorts == null) {
return ports;
}
for(Object js... | java |
public void fail(Throwable t) {
if (!failed) {
if (doneHandler != null) {
doneHandler.handle(new DefaultFutureResult<T>(t));
} else {
cause = t;
}
failed = true;
}
} | java |
public CountingCompletionHandler<T> setHandler(Handler<AsyncResult<T>> doneHandler) {
this.doneHandler = doneHandler;
checkDone();
return this;
} | java |
private void checkDone() {
if (doneHandler != null) {
if (cause != null) {
doneHandler.handle(new DefaultFutureResult<T>(cause));
} else {
if (count == required) {
doneHandler.handle(new DefaultFutureResult<T>((T) null));
}
}
}
} | java |
private void setup(final Handler<AsyncResult<Void>> doneHandler) {
// Retrieve the component context from the coordinator (the current cluster).
// If the context has changed due to a network configuration change, the
// internal context and input/output connections will be automatically updated.
log.de... | java |
public void start() {
input.messageHandler(new Handler<Object>() {
@Override
public void handle(Object message) {
output.send(message);
pumped++;
}
});
} | java |
public static <T extends Output<T>> Feeder<T> createFeeder(T output) {
return new Feeder<T>(output);
} | java |
private void doFeed() {
if (fed && !output.sendQueueFull()) {
fed = false;
vertx.runOnContext(feedRunner);
} else {
feedTimer = vertx.setTimer(feedDelay, recursiveRunner);
}
} | java |
public static Component createComponent(Vertx vertx, Container container) {
InstanceContext context = parseContext(container.config());
return new DefaultComponentFactory().setVertx(vertx).setContainer(container).createComponent(context, new DefaultCluster(context.component().network().cluster(), vertx, contain... | java |
public static JsonObject buildConfig(InstanceContext context, Cluster cluster) {
JsonObject config = context.component().config().copy();
return config.putObject("__context__", Contexts.serialize(context));
} | java |
private static InstanceContext parseContext(JsonObject config) {
JsonObject context = config.getObject("__context__");
if (context == null) {
throw new IllegalArgumentException("No component context found.");
}
config.removeField("__context__");
return Contexts.deserialize(context);
} | java |
private List<File> locateModules() {
File[] files = modRoot.listFiles();
List<File> modFiles = new ArrayList<>();
for (File file : files) {
if (file.isDirectory()) {
// Check to determine whether the directory is a valid module directory.
boolean isValid = true;
try {
... | java |
private File locateModule(ModuleIdentifier modID) {
File modDir = new File(modRoot, modID.toString());
if (modDir.exists()) {
return modDir;
}
return null;
} | java |
private void pullInDependencies(ModuleIdentifier modID, File modDir) {
// Load the module configuration file.
File modJsonFile = new File(modDir, MOD_JSON_FILE);
ModuleInfo info = loadModuleInfo(modID, modJsonFile);
// Pull in all dependencies according to the "includes" and "deploys" fields.
Modul... | java |
private File zipModule(ModuleIdentifier modID) {
File modDir = new File(modRoot, modID.toString());
if (!modDir.exists()) {
throw new PlatformManagerException("Cannot find module");
}
// Create a temporary directory in which to store the module and its dependencies.
File modRoot = new File(TE... | java |
private void zipDirectory(String zipFile, String dirToZip) {
File directory = new File(dirToZip);
try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(zipFile))) {
addDirectoryToZip(directory, directory, stream);
} catch (Exception e) {
throw new PlatformManagerException("Faile... | java |
private void addDirectoryToZip(File topDirectory, File directory, ZipOutputStream out) throws IOException {
Path top = Paths.get(topDirectory.getAbsolutePath());
File[] files = directory.listFiles();
byte[] buffer = new byte[BUFFER_SIZE];
for (int i = 0; i < files.length; i++) {
Path entry = Pat... | java |
private String[] parseIncludes(String sincludes) {
sincludes = sincludes.trim();
if ("".equals(sincludes)) {
return null;
}
String[] arr = sincludes.split(",");
if (arr != null) {
for (int i = 0; i < arr.length; i++) {
arr[i] = arr[i].trim();
}
}
return arr;
} | java |
private void unzipModuleData(File directory, File zipFile, boolean deleteZip) {
try (InputStream in = new BufferedInputStream(new FileInputStream(zipFile)); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(in))) {
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
Stri... | java |
@SuppressLint("ShowToast")
public Toast build() {
Toast toast = Toast.makeText(context, message, duration);
TextView toastMessage = setupToastView(toast);
setToastMessageTextColor(toastMessage);
setToastGravity(toast);
return toast;
} | java |
private void handleCreate(final NetworkContext context) {
log.debug(String.format("%s - Network configuration created in cluster: %s", NetworkManager.this, cluster.address()));
log.debug(String.format("%s - Scheduling network deployment task", NetworkManager.this));
tasks.runTask(new Handler<Task>() {
... | java |
private void undeployRemovedComponents(final NetworkContext context, final NetworkContext runningContext, final Handler<AsyncResult<Void>> doneHandler) {
// Undeploy any components that were removed from the network.
final List<ComponentContext<?>> removedComponents = new ArrayList<>();
for (ComponentContex... | java |
private void handleDelete() {
log.debug(String.format("%s - Network configuration removed from cluster: %s", NetworkManager.this, cluster.address()));
tasks.runTask(new Handler<Task>() {
@Override
public void handle(final Task task) {
unready(new Handler<AsyncResult<Void>>() {
@Ove... | java |
private void unready(final Handler<AsyncResult<Void>> doneHandler) {
if (currentContext != null && data != null) {
log.debug(String.format("%s - Pausing network", NetworkManager.this));
data.remove(currentContext.status(), new Handler<AsyncResult<String>>() {
@Override
public void handle... | java |
private void handleReady(String address) {
log.debug(String.format("%s - Received ready message from %s", NetworkManager.this, address));
ready.add(address);
checkReady();
} | java |
private void checkReady() {
if (allReady()) {
log.debug(String.format("%s - All components ready in network, starting components", NetworkManager.this));
// Set the network's status key to the current context version. This
// can be used by listeners to determine when a configuration change is com... | java |
private void handleUnready(String address) {
log.debug(String.format("%s - Received unready message from: %s", NetworkManager.this, address));
ready.remove(address);
checkUnready();
} | java |
private void checkUnready() {
if (!allReady()) {
log.debug(String.format("%s - Components not ready, pausing components", NetworkManager.this));
data.remove(currentContext.address(), new Handler<AsyncResult<String>>() {
@Override
public void handle(AsyncResult<String> result) {
... | java |
private boolean allReady() {
if (currentContext == null) return false;
List<InstanceContext> instances = new ArrayList<>();
boolean match = true;
outer: for (ComponentContext<?> component : currentContext.components()) {
instances.addAll(component.instances());
for (InstanceContext instance ... | java |
private void deployNetwork(final NetworkContext context, final Handler<AsyncResult<NetworkContext>> doneHandler) {
log.debug(String.format("%s - Deploying network", NetworkManager.this));
final CountingCompletionHandler<Void> complete = new CountingCompletionHandler<Void>(context.components().size());
compl... | java |
private void deployComponents(Collection<ComponentContext<?>> components, final CountingCompletionHandler<Void> counter) {
for (final ComponentContext<?> component : components) {
deployComponent(component, new Handler<AsyncResult<Void>>() {
@Override
public void handle(AsyncResult<Void> resul... | java |
private void deployInstances(List<InstanceContext> instances, final Handler<AsyncResult<Void>> doneHandler) {
final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(instances.size()).setHandler(doneHandler);
for (final InstanceContext instance : instances) {
// Before deployin... | java |
private void deployInstance(final InstanceContext instance, final CountingCompletionHandler<Void> counter) {
// First we need to select a node from the component's deployment group
// to which to deploy the component.
// If the component doesn't specify a group then deploy to any node in the cluster.
if... | java |
private void deployInstance(final Node node, final InstanceContext instance, final CountingCompletionHandler<Void> counter) {
data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() {
@Override
public void handle(AsyncResult<String> result) {
if (re... | java |
private void deployModule(final Node node, final InstanceContext instance, final CountingCompletionHandler<Void> counter) {
log.debug(String.format("%s - Deploying %s to %s", NetworkManager.this, instance.component().asModule().module(), node.address()));
node.deployModule(instance.component().asModule().module... | java |
private void installModules(final Node node, final NetworkContext context, final Handler<AsyncResult<Void>> doneHandler) {
List<ModuleContext> modules = new ArrayList<>();
for (ComponentContext<?> component : context.components()) {
if (component.isModule()) {
modules.add(component.asModule());
... | java |
private void installModule(final Node node, final ModuleContext module, final Handler<AsyncResult<Void>> doneHandler) {
node.installModule(module.module(), doneHandler);
} | java |
private void undeployComponents(Collection<ComponentContext<?>> components, final CountingCompletionHandler<Void> complete) {
for (final ComponentContext<?> component : components) {
final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(component.instances().size());
counte... | java |
private void undeployInstances(List<InstanceContext> instances, final CountingCompletionHandler<Void> counter) {
for (final InstanceContext instance : instances) {
if (instance.component().isModule()) {
undeployModule(instance, counter);
} else if (instance.component().isVerticle()) {
un... | java |
private void unwatchInstance(final InstanceContext instance, final CountingCompletionHandler<Void> counter) {
Handler<MapEvent<String, String>> watchHandler = watchHandlers.remove(instance.address());
if (watchHandler != null) {
data.unwatch(instance.status(), watchHandler, new Handler<AsyncResult<Void>>(... | java |
private void undeployModule(final InstanceContext instance, final CountingCompletionHandler<Void> counter) {
deploymentIDs.remove(instance.address(), new Handler<AsyncResult<String>>() {
@Override
public void handle(AsyncResult<String> result) {
if (result.failed()) {
counter.fail(resu... | java |
private void updateNetwork(final NetworkContext context, final Handler<AsyncResult<Void>> doneHandler) {
final CountingCompletionHandler<Void> complete = new CountingCompletionHandler<Void>(context.components().size());
complete.setHandler(new Handler<AsyncResult<Void>>() {
@Override
public void han... | java |
private void updateComponents(Collection<ComponentContext<?>> components, final CountingCompletionHandler<Void> complete) {
for (final ComponentContext<?> component : components) {
final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(component.instances().size());
counter.... | java |
private void updateInstances(List<InstanceContext> instances, final CountingCompletionHandler<Void> counter) {
for (final InstanceContext instance : instances) {
data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() {
@Override
public void handl... | java |
private void doNodeJoined(final Node node) {
tasks.runTask(new Handler<Task>() {
@Override
public void handle(final Task task) {
if (currentContext != null) {
log.info(String.format("%s - %s joined the cluster. Uploading components to new node", NetworkManager.this, node.address()));
... | java |
private void doNodeLeft(final Node node) {
tasks.runTask(new Handler<Task>() {
@Override
public void handle(final Task task) {
if (currentContext != null) {
log.info(String.format("%s - %s left the cluster. Reassigning components", NetworkManager.this, node.address()));
deplo... | java |
private void disconnect(final Handler<AsyncResult<Void>> doneHandler) {
eventBus.sendWithTimeout(inAddress, new JsonObject().putString("action", "disconnect"), 5000, new Handler<AsyncResult<Message<Boolean>>>() {
@Override
public void handle(AsyncResult<Message<Boolean>> result) {
if (result.fai... | java |
private void checkFull() {
if (!full && messages.size() >= maxQueueSize) {
full = true;
log.debug(String.format("%s - Connection to %s is full", this, context.target()));
}
} | java |
private void checkDrain() {
if (full && !paused && messages.size() < maxQueueSize / 2) {
full = false;
log.debug(String.format("%s - Connection to %s is drained", this, context.target()));
if (drainHandler != null) {
drainHandler.handle((Void) null);
}
}
} | java |
private void doAck(long id) {
// The other side of the connection has sent a message indicating which
// messages it has seen. We can clear any messages before the indicated ID.
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Received ack for messages up to %d, removing all previous messages... | java |
private void doFail(long id) {
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Received resend request for messages starting at %d", this, id));
}
// Ack all the entries before the given ID.
doAck(id);
// Now that all the entries before the given ID have been removed,
// just i... | java |
private void doPause(long id) {
log.debug(String.format("%s - Paused connection to %s", this, context.target()));
paused = true;
} | java |
private void doResume(long id) {
if (paused) {
log.debug(String.format("%s - Resumed connection to %s", this, context.target()));
paused = false;
checkDrain();
}
} | java |
void doGroupStart(String group, String name, Object args, String parent) {
checkOpen();
JsonObject message = createMessage(args)
.putString("group", group)
.putString("name", name)
.putString("parent", parent)
.putString("action", "startGroup");
if (open && !paused) {
i... | java |
void doGroupSend(String group, Object value) {
checkOpen();
JsonObject message = createMessage(value)
.putString("action", "group")
.putString("group", group);
if (open && !paused) {
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Group send: Group[group=%s, id=%d, me... | java |
void doGroupEnd(String group, Object args) {
checkOpen();
JsonObject message = createMessage(args)
.putString("action", "endGroup")
.putString("group", group);
if (open && !paused) {
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Group end: Group[group=%s, args=%s]",... | java |
void doBatchStart(String batch, Object args) {
checkOpen();
JsonObject message = createMessage(args)
.putString("batch", batch)
.putString("action", "startBatch");
if (open && !paused) {
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Batch start: Batch[batch=%s]", th... | java |
void doBatchEnd(String batch, Object args) {
checkOpen();
JsonObject message = createMessage(args)
.putString("action", "endBatch")
.putString("batch", batch);
if (open && !paused) {
if (log.isDebugEnabled()) {
log.debug(String.format("%s - Batch end: Batch[batch=%s, args=%s]",... | java |
private JsonObject createMessage(Object value) {
// Tag the message with a monotonically increasing ID. The ID
// will be used by the other side of the connection to guarantee
// ordering.
JsonObject message = serializer.serialize(value);
long id = currentMessage++;
message.putNumber("id", id);
... | java |
public static void checkNull(Object value, String message, Object... args) {
if (value != null) {
throw new IllegalArgumentException(String.format(message, args));
}
} | java |
public static void checkNotNull(Object value, String message, Object... args) {
if (value == null) {
throw new NullPointerException(String.format(message, args));
}
} | java |
public static void checkPositive(int number, String message, Object... args) {
if (number < 0) {
throw new IllegalArgumentException(String.format(message, args));
}
} | java |
public static void checkUri(String uri, String message, Object... args) {
try {
new URI(uri);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(String.format(message, args), e);
}
} | java |
void start(final Handler<OutputGroup> startHandler) {
connection.doGroupStart(id, name, args, parent);
this.startHandler = startHandler;
} | java |
public static PortLogger getLogger(Class<?> clazz, OutputCollector output) {
return getLogger(clazz.getCanonicalName(), output);
} | java |
public static PortLogger getLogger(String name, OutputCollector output) {
Args.checkNotNull(name, "logger name cannot be null");
Map<OutputCollector, PortLogger> loggers = PortLoggerFactory.loggers.get(name);
if (loggers == null) {
loggers = new HashMap<>();
PortLoggerFactory.loggers.put(name, l... | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.