repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
zutnop/telekom-workflow-engine
telekom-workflow-engine/src/main/java/ee/telekom/workflow/graph/el/ElUtil.java
ElUtil.isReservedVariable
public static boolean isReservedVariable( String variableName ){ return ReservedVariables.NOW.equalsIgnoreCase( variableName ) || ReservedVariables.WORKFLOW_INSTANCE_ID.equalsIgnoreCase( variableName ); }
java
public static boolean isReservedVariable( String variableName ){ return ReservedVariables.NOW.equalsIgnoreCase( variableName ) || ReservedVariables.WORKFLOW_INSTANCE_ID.equalsIgnoreCase( variableName ); }
[ "public", "static", "boolean", "isReservedVariable", "(", "String", "variableName", ")", "{", "return", "ReservedVariables", ".", "NOW", ".", "equalsIgnoreCase", "(", "variableName", ")", "||", "ReservedVariables", ".", "WORKFLOW_INSTANCE_ID", ".", "equalsIgnoreCase", ...
Checks if the given variable name is a reserved keyword and SHOULD NOT be used as a key for an Environment attribute.
[ "Checks", "if", "the", "given", "variable", "name", "is", "a", "reserved", "keyword", "and", "SHOULD", "NOT", "be", "used", "as", "a", "key", "for", "an", "Environment", "attribute", "." ]
f471f1f94013b3e2d56b4c9380e86e3a92c2ee29
https://github.com/zutnop/telekom-workflow-engine/blob/f471f1f94013b3e2d56b4c9380e86e3a92c2ee29/telekom-workflow-engine/src/main/java/ee/telekom/workflow/graph/el/ElUtil.java#L54-L56
train
zutnop/telekom-workflow-engine
telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java
TransitionBuilder.findIf
private Tree<Row> findIf( Tree<Row> pointer ){ while( !Type.IF.equals( pointer.getContent().getType() ) ){ pointer = pointer.getPrevious(); } return pointer; }
java
private Tree<Row> findIf( Tree<Row> pointer ){ while( !Type.IF.equals( pointer.getContent().getType() ) ){ pointer = pointer.getPrevious(); } return pointer; }
[ "private", "Tree", "<", "Row", ">", "findIf", "(", "Tree", "<", "Row", ">", "pointer", ")", "{", "while", "(", "!", "Type", ".", "IF", ".", "equals", "(", "pointer", ".", "getContent", "(", ")", ".", "getType", "(", ")", ")", ")", "{", "pointer",...
Finds the associate IF for an ELSE_IF, ELSE or END_IF pointer.
[ "Finds", "the", "associate", "IF", "for", "an", "ELSE_IF", "ELSE", "or", "END_IF", "pointer", "." ]
f471f1f94013b3e2d56b4c9380e86e3a92c2ee29
https://github.com/zutnop/telekom-workflow-engine/blob/f471f1f94013b3e2d56b4c9380e86e3a92c2ee29/telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java#L153-L158
train
zutnop/telekom-workflow-engine
telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java
TransitionBuilder.findEndIf
private Tree<Row> findEndIf( Tree<Row> pointer ){ while( !Type.END_IF.equals( pointer.getContent().getType() ) ){ pointer = pointer.getNext(); } return pointer; }
java
private Tree<Row> findEndIf( Tree<Row> pointer ){ while( !Type.END_IF.equals( pointer.getContent().getType() ) ){ pointer = pointer.getNext(); } return pointer; }
[ "private", "Tree", "<", "Row", ">", "findEndIf", "(", "Tree", "<", "Row", ">", "pointer", ")", "{", "while", "(", "!", "Type", ".", "END_IF", ".", "equals", "(", "pointer", ".", "getContent", "(", ")", ".", "getType", "(", ")", ")", ")", "{", "po...
Finds the associate END_IF for an IF, ELSE_IF or ELSE pointer
[ "Finds", "the", "associate", "END_IF", "for", "an", "IF", "ELSE_IF", "or", "ELSE", "pointer" ]
f471f1f94013b3e2d56b4c9380e86e3a92c2ee29
https://github.com/zutnop/telekom-workflow-engine/blob/f471f1f94013b3e2d56b4c9380e86e3a92c2ee29/telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java#L163-L168
train
zutnop/telekom-workflow-engine
telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java
TransitionBuilder.findNext
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.getNext(); } } // The given tree-node was last in its block. Then we return the // the block closing tree-node. Tree<Row> parent = pointer.getParent(); Type parentType = parent.getContent().getType(); if( Type.WHILE_DO_BEGIN.equals( parentType ) ){ return parent.getNext(); } else if( Type.DO_WHILE_BEGIN.equals( parentType ) ){ return parent.getNext(); } if( Type.BRANCH.equals( parentType ) ){ Tree<Row> join = parent.getParent().getNext(); return join; } else if( Type.IF.equals( parentType ) || Type.ELSE_IF.equals( parentType ) || Type.ELSE.equals( parentType ) ){ Tree<Row> endIf = findEndIf( parent ); return endIf; } else{ throw new IllegalStateException( "Unknown containting block type for row " + parent.getContent() ); } }
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.getNext(); } } // The given tree-node was last in its block. Then we return the // the block closing tree-node. Tree<Row> parent = pointer.getParent(); Type parentType = parent.getContent().getType(); if( Type.WHILE_DO_BEGIN.equals( parentType ) ){ return parent.getNext(); } else if( Type.DO_WHILE_BEGIN.equals( parentType ) ){ return parent.getNext(); } if( Type.BRANCH.equals( parentType ) ){ Tree<Row> join = parent.getParent().getNext(); return join; } else if( Type.IF.equals( parentType ) || Type.ELSE_IF.equals( parentType ) || Type.ELSE.equals( parentType ) ){ Tree<Row> endIf = findEndIf( parent ); return endIf; } else{ throw new IllegalStateException( "Unknown containting block type for row " + parent.getContent() ); } }
[ "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...
Finds the following node which to create a transition to. Supports tree-nodes that are not the last in their block and those which are last.
[ "Finds", "the", "following", "node", "which", "to", "create", "a", "transition", "to", ".", "Supports", "tree", "-", "nodes", "that", "are", "not", "the", "last", "in", "their", "block", "and", "those", "which", "are", "last", "." ]
f471f1f94013b3e2d56b4c9380e86e3a92c2ee29
https://github.com/zutnop/telekom-workflow-engine/blob/f471f1f94013b3e2d56b4c9380e86e3a92c2ee29/telekom-workflow-engine/src/main/java/ee/telekom/workflow/api/TransitionBuilder.java#L183-L215
train
seedstack/business
core/src/main/java/org/seedstack/business/internal/utils/MethodMatcher.java
MethodMatcher.findMatchingMethod
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 the return type is not specified (i.e null) we only check the parameters boolean matchReturnType = returnType == null || returnType.equals(method.getReturnType()); if (checkParams(parameterTypes, params) && matchReturnType) { if (checkedMethod == null) { checkedMethod = method; } else { throw BusinessException.createNew(BusinessErrorCode.AMBIGUOUS_METHOD_FOUND) .put("method1", method) .put("method2", checkedMethod) .put("object", classToInspect.getSimpleName()) .put("parameters", params); } } } return checkedMethod; }
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 the return type is not specified (i.e null) we only check the parameters boolean matchReturnType = returnType == null || returnType.equals(method.getReturnType()); if (checkParams(parameterTypes, params) && matchReturnType) { if (checkedMethod == null) { checkedMethod = method; } else { throw BusinessException.createNew(BusinessErrorCode.AMBIGUOUS_METHOD_FOUND) .put("method1", method) .put("method2", checkedMethod) .put("object", classToInspect.getSimpleName()) .put("parameters", params); } } } return checkedMethod; }
[ "public", "static", "Method", "findMatchingMethod", "(", "Class", "<", "?", ">", "classToInspect", ",", "Class", "<", "?", ">", "returnType", ",", "Object", "...", "params", ")", "{", "Method", "[", "]", "methods", "=", "classToInspect", ".", "getMethods", ...
Finds a method matching the given parameters and return type.
[ "Finds", "a", "method", "matching", "the", "given", "parameters", "and", "return", "type", "." ]
55b3e861fe152e9b125ebc69daa91a682deeae8a
https://github.com/seedstack/business/blob/55b3e861fe152e9b125ebc69daa91a682deeae8a/core/src/main/java/org/seedstack/business/internal/utils/MethodMatcher.java#L27-L48
train
seedstack/business
core/src/main/java/org/seedstack/business/internal/utils/MethodMatcher.java
MethodMatcher.findMatchingConstructor
@SuppressWarnings("unchecked") public static <T> Constructor<T> findMatchingConstructor(Class<T> classToInspect, Object... params) { Constructor<T> checkedConstructors = null; for (Constructor<?> constructor : classToInspect.getDeclaredConstructors()) { Type[] parameterTypes = constructor.getParameterTypes(); if (parameterTypes.length == params.length && checkParameterTypes(parameterTypes, params)) { if (checkedConstructors == null) { checkedConstructors = (Constructor<T>) constructor; } else { throw BusinessException.createNew(BusinessErrorCode.AMBIGUOUS_CONSTRUCTOR_FOUND) .put("constructor1", constructor) .put("constructor2", checkedConstructors) .put("object", classToInspect.getSimpleName()) .put("parameters", params); } } } return checkedConstructors; }
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 = constructor.getParameterTypes(); if (parameterTypes.length == params.length && checkParameterTypes(parameterTypes, params)) { if (checkedConstructors == null) { checkedConstructors = (Constructor<T>) constructor; } else { throw BusinessException.createNew(BusinessErrorCode.AMBIGUOUS_CONSTRUCTOR_FOUND) .put("constructor1", constructor) .put("constructor2", checkedConstructors) .put("object", classToInspect.getSimpleName()) .put("parameters", params); } } } return checkedConstructors; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", ">", "Constructor", "<", "T", ">", "findMatchingConstructor", "(", "Class", "<", "T", ">", "classToInspect", ",", "Object", "...", "params", ")", "{", "Constructor", "<", "T", ...
Finds a constructor matching the given parameters.
[ "Finds", "a", "constructor", "matching", "the", "given", "parameters", "." ]
55b3e861fe152e9b125ebc69daa91a682deeae8a
https://github.com/seedstack/business/blob/55b3e861fe152e9b125ebc69daa91a682deeae8a/core/src/main/java/org/seedstack/business/internal/utils/MethodMatcher.java#L53-L71
train
seedstack/business
core/src/main/java/org/seedstack/business/spi/BaseDtoInfoResolver.java
BaseDtoInfoResolver.createFromFactory
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 signature determined with the previously // extracted parameters Method factoryMethod; boolean useDefaultFactory = false; try { factoryMethod = MethodMatcher.findMatchingMethod(factory.getClass(), aggregateClass, parameters); if (factoryMethod == null) { useDefaultFactory = true; } } catch (Exception e) { throw BusinessException.wrap(e, BusinessErrorCode.UNABLE_TO_FIND_FACTORY_METHOD) .put("aggregateClass", aggregateClass.getName()) .put("parameters", Arrays.toString(parameters)); } // Invoke the factory to create the aggregate root try { if (useDefaultFactory) { return factory.create(parameters); } else { if (parameters.length == 0) { return ReflectUtils.invoke(factoryMethod, factory); } else { return ReflectUtils.invoke(factoryMethod, factory, parameters); } } } catch (Exception e) { throw BusinessException.wrap(e, BusinessErrorCode.UNABLE_TO_INVOKE_FACTORY_METHOD) .put("aggregateClass", aggregateClass.getName()) .put("factoryClass", factory.getClass() .getName()) .put("factoryMethod", Optional.ofNullable(factoryMethod) .map(Method::getName) .orElse("create")) .put("parameters", Arrays.toString(parameters)); } }
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 signature determined with the previously // extracted parameters Method factoryMethod; boolean useDefaultFactory = false; try { factoryMethod = MethodMatcher.findMatchingMethod(factory.getClass(), aggregateClass, parameters); if (factoryMethod == null) { useDefaultFactory = true; } } catch (Exception e) { throw BusinessException.wrap(e, BusinessErrorCode.UNABLE_TO_FIND_FACTORY_METHOD) .put("aggregateClass", aggregateClass.getName()) .put("parameters", Arrays.toString(parameters)); } // Invoke the factory to create the aggregate root try { if (useDefaultFactory) { return factory.create(parameters); } else { if (parameters.length == 0) { return ReflectUtils.invoke(factoryMethod, factory); } else { return ReflectUtils.invoke(factoryMethod, factory, parameters); } } } catch (Exception e) { throw BusinessException.wrap(e, BusinessErrorCode.UNABLE_TO_INVOKE_FACTORY_METHOD) .put("aggregateClass", aggregateClass.getName()) .put("factoryClass", factory.getClass() .getName()) .put("factoryMethod", Optional.ofNullable(factoryMethod) .map(Method::getName) .orElse("create")) .put("parameters", Arrays.toString(parameters)); } }
[ "protected", "<", "A", "extends", "AggregateRoot", "<", "?", ">", ">", "A", "createFromFactory", "(", "Class", "<", "A", ">", "aggregateClass", ",", "Object", "...", "parameters", ")", "{", "checkNotNull", "(", "aggregateClass", ")", ";", "checkNotNull", "("...
Implements the logic to create an aggregate. @param aggregateClass the aggregate class. @param parameters the parameters to pass to the factory if any. @param <A> the type of the aggregate root. @return the aggregate root.
[ "Implements", "the", "logic", "to", "create", "an", "aggregate", "." ]
55b3e861fe152e9b125ebc69daa91a682deeae8a
https://github.com/seedstack/business/blob/55b3e861fe152e9b125ebc69daa91a682deeae8a/core/src/main/java/org/seedstack/business/spi/BaseDtoInfoResolver.java#L75-L117
train
sap-production/xcode-maven-plugin
modules/xcode-maven-plugin/src/main/java/com/sap/prd/mobile/ios/mios/DomUtils.java
DomUtils.serialize
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 IllegalArgumentException("No output stream provided"); if (encoding == null || encoding.isEmpty()) throw new IllegalArgumentException("No encoding provided."); final TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", Integer.valueOf(2)); final Transformer t = transformerFactory.newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.ENCODING, encoding); final OutputStreamWriter osw = new OutputStreamWriter(os, encoding); t.transform(new DOMSource(doc), new StreamResult(osw)); osw.flush(); }
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 IllegalArgumentException("No output stream provided"); if (encoding == null || encoding.isEmpty()) throw new IllegalArgumentException("No encoding provided."); final TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", Integer.valueOf(2)); final Transformer t = transformerFactory.newTransformer(); t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); t.setOutputProperty(OutputKeys.METHOD, "xml"); t.setOutputProperty(OutputKeys.INDENT, "yes"); t.setOutputProperty(OutputKeys.ENCODING, encoding); final OutputStreamWriter osw = new OutputStreamWriter(os, encoding); t.transform(new DOMSource(doc), new StreamResult(osw)); osw.flush(); }
[ "static", "void", "serialize", "(", "final", "Document", "doc", ",", "final", "OutputStream", "os", ",", "final", "String", "encoding", ")", "throws", "TransformerFactoryConfigurationError", ",", "TransformerException", ",", "IOException", "{", "if", "(", "doc", "...
Serializes a DOM. The OutputStream handed over to this method is not closed inside this method.
[ "Serializes", "a", "DOM", ".", "The", "OutputStream", "handed", "over", "to", "this", "method", "is", "not", "closed", "inside", "this", "method", "." ]
3f8aa380f501a1d7602f33fef2f6348354e7eb7c
https://github.com/sap-production/xcode-maven-plugin/blob/3f8aa380f501a1d7602f33fef2f6348354e7eb7c/modules/xcode-maven-plugin/src/main/java/com/sap/prd/mobile/ios/mios/DomUtils.java#L54-L78
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Messages/TransmittableSysexMessage.java
TransmittableSysexMessage.toByteArray
@Override public byte[] toByteArray() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(16); outputStream.write(commandByte); outputStream.write(sysexCommandByte); if (serialize(outputStream)) { outputStream.write(CommandBytes.END_SYSEX.getCommandByte()); return outputStream.toByteArray(); } return null; }
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()); return outputStream.toByteArray(); } return null; }
[ "@", "Override", "public", "byte", "[", "]", "toByteArray", "(", ")", "{", "ByteArrayOutputStream", "outputStream", "=", "new", "ByteArrayOutputStream", "(", "16", ")", ";", "outputStream", ".", "write", "(", "commandByte", ")", ";", "outputStream", ".", "writ...
Combine the SysexCommandByte and the serialized sysex message packet together to form a Firmata supported sysex byte packet to be sent over the SerialPort. @return byte[] array representing the full Firmata sysex command packet to be sent to the Firmata device.
[ "Combine", "the", "SysexCommandByte", "and", "the", "serialized", "sysex", "message", "packet", "together", "to", "form", "a", "Firmata", "supported", "sysex", "byte", "packet", "to", "be", "sent", "over", "the", "SerialPort", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Messages/TransmittableSysexMessage.java#L46-L59
train
yongjhih/SwitchPreferenceCompat
app/src/main/java/com/cgollner/unclouded/preferences/sample/SettingsActivity.java
SettingsActivity.isValidFragment
@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
@Override protected boolean isValidFragment(String fragmentName) { Boolean knownFrag = false; for (Class<?> cls : INNER_CLASSES) { if ( cls.getName().equals(fragmentName) ){ knownFrag = true; break; } } return knownFrag; }
[ "@", "Override", "protected", "boolean", "isValidFragment", "(", "String", "fragmentName", ")", "{", "Boolean", "knownFrag", "=", "false", ";", "for", "(", "Class", "<", "?", ">", "cls", ":", "INNER_CLASSES", ")", "{", "if", "(", "cls", ".", "getName", "...
Google found a 'security vulnerability' and imposed this hack. Have to check this fragment was actually conceived by this activity.
[ "Google", "found", "a", "security", "vulnerability", "and", "imposed", "this", "hack", ".", "Have", "to", "check", "this", "fragment", "was", "actually", "conceived", "by", "this", "activity", "." ]
e7d4ff0d51b882b88c3d537ef7428ca9e4e3d492
https://github.com/yongjhih/SwitchPreferenceCompat/blob/e7d4ff0d51b882b88c3d537ef7428ca9e4e3d492/app/src/main/java/com/cgollner/unclouded/preferences/sample/SettingsActivity.java#L51-L67
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Messages/TransmittableMessage.java
TransmittableMessage.toByteArray
public byte[] toByteArray() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32); outputStream.write(commandByte); if (serialize(outputStream)) { return outputStream.toByteArray(); } return null; }
java
public byte[] toByteArray() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32); outputStream.write(commandByte); if (serialize(outputStream)) { return outputStream.toByteArray(); } return null; }
[ "public", "byte", "[", "]", "toByteArray", "(", ")", "{", "ByteArrayOutputStream", "outputStream", "=", "new", "ByteArrayOutputStream", "(", "32", ")", ";", "outputStream", ".", "write", "(", "commandByte", ")", ";", "if", "(", "serialize", "(", "outputStream"...
Combine the CommandByte and the serialized message packet together to form a Firmata supported byte packet to be sent over the SerialPort. @return true if no errors building message
[ "Combine", "the", "CommandByte", "and", "the", "serialized", "message", "packet", "together", "to", "form", "a", "Firmata", "supported", "byte", "packet", "to", "be", "sent", "over", "the", "SerialPort", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Messages/TransmittableMessage.java#L51-L61
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/PortAdapters/SerialPort.java
SerialPort.fireEvent
protected void fireEvent(SerialPortEventTypes eventType) { executor.submit(new Runnable() { @Override public void run() { for (SerialPortEventListener listener : eventListeners) { listener.serialEvent(new SerialPortEvent(eventType)); } } }); }
java
protected void fireEvent(SerialPortEventTypes eventType) { executor.submit(new Runnable() { @Override public void run() { for (SerialPortEventListener listener : eventListeners) { listener.serialEvent(new SerialPortEvent(eventType)); } } }); }
[ "protected", "void", "fireEvent", "(", "SerialPortEventTypes", "eventType", ")", "{", "executor", ".", "submit", "(", "new", "Runnable", "(", ")", "{", "@", "Override", "public", "void", "run", "(", ")", "{", "for", "(", "SerialPortEventListener", "listener", ...
Tell the client if there is data available, etc.
[ "Tell", "the", "client", "if", "there", "is", "data", "available", "etc", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/PortAdapters/SerialPort.java#L70-L80
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Messages/SysexCapabilityMessage.java
SysexCapabilityMessage.getPinCapabilities
public ArrayList<PinCapability> getPinCapabilities(Integer pin) { if (pinCapabilities.size() >= pin) { return pinCapabilities.get(pin); } return null; }
java
public ArrayList<PinCapability> getPinCapabilities(Integer pin) { if (pinCapabilities.size() >= pin) { return pinCapabilities.get(pin); } return null; }
[ "public", "ArrayList", "<", "PinCapability", ">", "getPinCapabilities", "(", "Integer", "pin", ")", "{", "if", "(", "pinCapabilities", ".", "size", "(", ")", ">=", "pin", ")", "{", "return", "pinCapabilities", ".", "get", "(", "pin", ")", ";", "}", "retu...
Get Pin Capabilities Get a list of modes that a given pin supports. @param pin Integer value representing the Firmata pin that we want to know the supported capabilities of. @return ArrayList of PinCapability that the given pin index supports.\ Null if there is no pin at the given index.
[ "Get", "Pin", "Capabilities", "Get", "a", "list", "of", "modes", "that", "a", "given", "pin", "supports", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Messages/SysexCapabilityMessage.java#L36-L41
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.addMessageListener
public void addMessageListener(Integer channel, MessageListener<? extends Message> messageListener) { addListener(channel, messageListener.getMessageType(), messageListener); }
java
public void addMessageListener(Integer channel, MessageListener<? extends Message> messageListener) { addListener(channel, messageListener.getMessageType(), messageListener); }
[ "public", "void", "addMessageListener", "(", "Integer", "channel", ",", "MessageListener", "<", "?", "extends", "Message", ">", "messageListener", ")", "{", "addListener", "(", "channel", ",", "messageListener", ".", "getMessageType", "(", ")", ",", "messageListen...
Add a messageListener to the Firmta object which will fire whenever a matching message is received over the SerialPort that corresponds to the given channel. @param channel Integer indicating the specific channel or pin to listen on @param messageListener MessageListener object to handle a received Message event over the SerialPort.
[ "Add", "a", "messageListener", "to", "the", "Firmta", "object", "which", "will", "fire", "whenever", "a", "matching", "message", "is", "received", "over", "the", "SerialPort", "that", "corresponds", "to", "the", "given", "channel", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L174-L176
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.addMessageListener
public void addMessageListener(DigitalChannel channel, MessageListener<? extends Message> messageListener) { addListener(channel.getIdentifier(), messageListener.getMessageType(), messageListener); }
java
public void addMessageListener(DigitalChannel channel, MessageListener<? extends Message> messageListener) { addListener(channel.getIdentifier(), messageListener.getMessageType(), messageListener); }
[ "public", "void", "addMessageListener", "(", "DigitalChannel", "channel", ",", "MessageListener", "<", "?", "extends", "Message", ">", "messageListener", ")", "{", "addListener", "(", "channel", ".", "getIdentifier", "(", ")", ",", "messageListener", ".", "getMess...
Add a messageListener to the Firmata object which will fire whenever a matching message is received over the SerialPort that corresponds to the given DigitalChannel. @param channel DigitalChannel to listen on @param messageListener MessageListener object to handle a received Message event over the SerialPort.
[ "Add", "a", "messageListener", "to", "the", "Firmata", "object", "which", "will", "fire", "whenever", "a", "matching", "message", "is", "received", "over", "the", "SerialPort", "that", "corresponds", "to", "the", "given", "DigitalChannel", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L185-L187
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.addMessageListener
public void addMessageListener(Class<? extends Message> messageClass, MessageListener<Message> messageListener) { addMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener); }
java
public void addMessageListener(Class<? extends Message> messageClass, MessageListener<Message> messageListener) { addMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener); }
[ "public", "void", "addMessageListener", "(", "Class", "<", "?", "extends", "Message", ">", "messageClass", ",", "MessageListener", "<", "Message", ">", "messageListener", ")", "{", "addMessageListener", "(", "messageListener", ".", "getChannelIdentifier", "(", ")", ...
Add a generic message listener to listen for a specific type of message. Useful if you want to combine several or more message handlers into one bucket. @param messageClass Message class to listen to from the project board. @param messageListener (Generic)Listener that will fire whenever the message type is received.
[ "Add", "a", "generic", "message", "listener", "to", "listen", "for", "a", "specific", "type", "of", "message", ".", "Useful", "if", "you", "want", "to", "combine", "several", "or", "more", "message", "handlers", "into", "one", "bucket", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L195-L197
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.removeMessageListener
public void removeMessageListener(Class<? extends Message> messageClass, MessageListener<Message> messageListener) { removeMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener); }
java
public void removeMessageListener(Class<? extends Message> messageClass, MessageListener<Message> messageListener) { removeMessageListener(messageListener.getChannelIdentifier(), messageClass, messageListener); }
[ "public", "void", "removeMessageListener", "(", "Class", "<", "?", "extends", "Message", ">", "messageClass", ",", "MessageListener", "<", "Message", ">", "messageListener", ")", "{", "removeMessageListener", "(", "messageListener", ".", "getChannelIdentifier", "(", ...
Remove a generic message listener from listening to a specific type of message. @param messageClass Message class to stop listening to. @param messageListener (Generic)Listener to remove from the listener list for the given messageClass.
[ "Remove", "a", "generic", "message", "listener", "from", "listening", "to", "a", "specific", "type", "of", "message", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L268-L271
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.sendMessage
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("Transmitting message {}. Bytes: {}", message.getClass().getSimpleName(), FirmataHelper.bytesToHexString(message.toByteArray())); serialPort.getOutputStream().write(message.toByteArray()); return true; } catch (IOException e) { log.error("Unable to transmit message {} through serial port", message.getClass().getName()); stop(); } return false; }
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("Transmitting message {}. Bytes: {}", message.getClass().getSimpleName(), FirmataHelper.bytesToHexString(message.toByteArray())); serialPort.getOutputStream().write(message.toByteArray()); return true; } catch (IOException e) { log.error("Unable to transmit message {} through serial port", message.getClass().getName()); stop(); } return false; }
[ "public", "synchronized", "Boolean", "sendMessage", "(", "TransmittableMessage", "message", ")", "{", "if", "(", "!", "start", "(", ")", ")", "{", "log", ".", "error", "(", "\"Firmata library is not connected / started! Cannot send message {}\"", ",", "message", ".", ...
Send a Message over the serial port to a Firmata supported device. @param message TransmittableMessage object used to translate a series of bytes to the SerialPort. @return True if the Message sent. False if the Message was not sent.
[ "Send", "a", "Message", "over", "the", "serial", "port", "to", "a", "Firmata", "supported", "device", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L316-L334
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.sendRaw
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.getOutputStream().write(rawBytes); return true; } catch (IOException e) { log.error("Unable to transmit raw bytes through serial port. Bytes: {}", FirmataHelper.bytesToHexString(rawBytes)); stop(); } return false; }
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.getOutputStream().write(rawBytes); return true; } catch (IOException e) { log.error("Unable to transmit raw bytes through serial port. Bytes: {}", FirmataHelper.bytesToHexString(rawBytes)); stop(); } return false; }
[ "public", "synchronized", "Boolean", "sendRaw", "(", "byte", "...", "rawBytes", ")", "{", "if", "(", "!", "start", "(", ")", ")", "{", "log", ".", "error", "(", "\"Firmata library is not connected / started! Cannot send bytes {}\"", ",", "FirmataHelper", ".", "byt...
Send a series of raw bytes over the serial port to a Firmata supported device. @param rawBytes byte array to be sent over the SerialPort OutputStream. @return True if the bytes were sent. False if the bytes were not sent.
[ "Send", "a", "series", "of", "raw", "bytes", "over", "the", "serial", "port", "to", "a", "Firmata", "supported", "device", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L369-L386
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.start
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("Configuration is {}", configuration); stop(); return false; } if (configuration.getTestProtocolCommunication()) { if (!testProtocolCommunication()) { stop(); return false; } } started = true; return true; }
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("Configuration is {}", configuration); stop(); return false; } if (configuration.getTestProtocolCommunication()) { if (!testProtocolCommunication()) { stop(); return false; } } started = true; return true; }
[ "public", "synchronized", "Boolean", "start", "(", ")", "{", "if", "(", "started", ")", "{", "return", "true", ";", "}", "createSerialPort", "(", ")", ";", "serialPort", ".", "addEventListener", "(", "this", ")", ";", "if", "(", "!", "serialPort", ".", ...
Starts the firmata library. If the library is already started this will just return true. Starts the SerialPort and handlers, and ensures the attached device is able to communicate with our library. This will return an UnsupportedDevice exception if the attached device does not meet the library requirements. @return True if the library started. False if the library failed to start.
[ "Starts", "the", "firmata", "library", ".", "If", "the", "library", "is", "already", "started", "this", "will", "just", "return", "true", ".", "Starts", "the", "SerialPort", "and", "handlers", "and", "ensures", "the", "attached", "device", "is", "able", "to"...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L398-L423
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.stop
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); return false; } started = false; return true; }
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); return false; } started = false; return true; }
[ "public", "synchronized", "Boolean", "stop", "(", ")", "{", "if", "(", "serialPort", "!=", "null", ")", "{", "serialPort", ".", "removeEventListener", "(", "this", ")", ";", "}", "if", "(", "!", "removeSerialPort", "(", ")", ")", "{", "log", ".", "erro...
Stops the Firmata library. If the library is already stopped, this will still attempt to stop anything that may still be lingering. Take note that many calls could eventually result in noticeable cpu usage. @return True if the library has stopped. False if there was an error stopping the library.
[ "Stops", "the", "Firmata", "library", ".", "If", "the", "library", "is", "already", "stopped", "this", "will", "still", "attempt", "to", "stop", "anything", "that", "may", "still", "be", "lingering", ".", "Take", "note", "that", "many", "calls", "could", "...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L431-L444
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.createSerialPort
private void createSerialPort() { Constructor<? extends SerialPort> constructor; try { constructor = configuration.getSerialPortAdapterClass().getDeclaredConstructor( String.class, Integer.class, SerialPortDataBits.class, SerialPortStopBits.class, SerialPortParity.class); } catch (NoSuchMethodException e) { log.error("Unable to construct SerialPort object. Programming error. Your class adapter must support " + "a constructor with input args of" + "YourSerialPort(String.class, Integer.class, SerialPortDataBits.class, " + "SerialPortStopBits.class, SerialPortParity.class);"); e.printStackTrace(); throw new RuntimeException("Cannot construct SerialPort adapter!"); } try { serialPort = constructor.newInstance( configuration.getSerialPortID(), configuration.getSerialPortBaudRate(), configuration.getSerialPortDataBits(), configuration.getSerialPortStopBits(), configuration.getSerialPortParity()); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { log.error("Unable to construct SerialPort object. Programming error. Instantiation error. {}", e.getMessage()); e.printStackTrace(); throw new RuntimeException("Cannot construct SerialPort adapter!"); } }
java
private void createSerialPort() { Constructor<? extends SerialPort> constructor; try { constructor = configuration.getSerialPortAdapterClass().getDeclaredConstructor( String.class, Integer.class, SerialPortDataBits.class, SerialPortStopBits.class, SerialPortParity.class); } catch (NoSuchMethodException e) { log.error("Unable to construct SerialPort object. Programming error. Your class adapter must support " + "a constructor with input args of" + "YourSerialPort(String.class, Integer.class, SerialPortDataBits.class, " + "SerialPortStopBits.class, SerialPortParity.class);"); e.printStackTrace(); throw new RuntimeException("Cannot construct SerialPort adapter!"); } try { serialPort = constructor.newInstance( configuration.getSerialPortID(), configuration.getSerialPortBaudRate(), configuration.getSerialPortDataBits(), configuration.getSerialPortStopBits(), configuration.getSerialPortParity()); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { log.error("Unable to construct SerialPort object. Programming error. Instantiation error. {}", e.getMessage()); e.printStackTrace(); throw new RuntimeException("Cannot construct SerialPort adapter!"); } }
[ "private", "void", "createSerialPort", "(", ")", "{", "Constructor", "<", "?", "extends", "SerialPort", ">", "constructor", ";", "try", "{", "constructor", "=", "configuration", ".", "getSerialPortAdapterClass", "(", ")", ".", "getDeclaredConstructor", "(", "Strin...
Generate the SerialPort object using the SerialPort adapter class provided in the FirmataConfiguration If there is any issue constructing this object, toss a RuntimeException, as this is a developer error in implementing the SerialPort adapter for this library.
[ "Generate", "the", "SerialPort", "object", "using", "the", "SerialPort", "adapter", "class", "provided", "in", "the", "FirmataConfiguration", "If", "there", "is", "any", "issue", "constructing", "this", "object", "toss", "a", "RuntimeException", "as", "this", "is"...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L499-L528
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.removeSerialPort
private Boolean removeSerialPort() { Boolean ret = true; if (serialPort != null) { ret = serialPort.disconnect(); serialPort = null; } return ret; }
java
private Boolean removeSerialPort() { Boolean ret = true; if (serialPort != null) { ret = serialPort.disconnect(); serialPort = null; } return ret; }
[ "private", "Boolean", "removeSerialPort", "(", ")", "{", "Boolean", "ret", "=", "true", ";", "if", "(", "serialPort", "!=", "null", ")", "{", "ret", "=", "serialPort", ".", "disconnect", "(", ")", ";", "serialPort", "=", "null", ";", "}", "return", "re...
Disconnect from the SerialPort object that we are communicating with over the Firmata protocol. @return True if the SerialPort was closed. False if the port failed to close.
[ "Disconnect", "from", "the", "SerialPort", "object", "that", "we", "are", "communicating", "with", "over", "the", "Firmata", "protocol", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L535-L544
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.handleDataAvailable
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 trying to read serial port."); stop(); return; } Message message = configuration.getCommandParser().handleInputStream(inputByte, inputStream); if (message != null) { log.debug("Routing message {}", message.getClass().getSimpleName()); routeMessage(message); } } } catch (IOException e) { log.error("IO Error reading from serial port. Closing connection."); e.printStackTrace(); stop(); } }
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 trying to read serial port."); stop(); return; } Message message = configuration.getCommandParser().handleInputStream(inputByte, inputStream); if (message != null) { log.debug("Routing message {}", message.getClass().getSimpleName()); routeMessage(message); } } } catch (IOException e) { log.error("IO Error reading from serial port. Closing connection."); e.printStackTrace(); stop(); } }
[ "private", "void", "handleDataAvailable", "(", ")", "{", "InputStream", "inputStream", "=", "serialPort", ".", "getInputStream", "(", ")", ";", "try", "{", "while", "(", "inputStream", ".", "available", "(", ")", ">", "0", ")", "{", "byte", "inputByte", "=...
Handles the SerialPort input stream and builds a message object if a detected CommandByte is discovered over the communications stream.
[ "Handles", "the", "SerialPort", "input", "stream", "and", "builds", "a", "message", "object", "if", "a", "detected", "CommandByte", "is", "discovered", "over", "the", "communications", "stream", "." ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L564-L588
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.routeMessage
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); } // Dispatch message to all generic listeners if (messageListenerMap.containsKey(Message.class)) { dispatchMessage(messageListenerMap.get(Message.class), message); } }
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); } // Dispatch message to all generic listeners if (messageListenerMap.containsKey(Message.class)) { dispatchMessage(messageListenerMap.get(Message.class), message); } }
[ "private", "void", "routeMessage", "(", "Message", "message", ")", "{", "Class", "messageClass", "=", "message", ".", "getClass", "(", ")", ";", "// Dispatch message to all specific listeners for the message class type", "if", "(", "messageListenerMap", ".", "containsKey"...
Route a Message object built from data over the SerialPort communication line to a corresponding MessageListener array designed to handle and interpret the object for processing in the client code. @param message Firmata Message to be routed to the registered listeners.
[ "Route", "a", "Message", "object", "built", "from", "data", "over", "the", "SerialPort", "communication", "line", "to", "a", "corresponding", "MessageListener", "array", "designed", "to", "handle", "and", "interpret", "the", "object", "for", "processing", "in", ...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L596-L608
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java
Firmata.dispatchMessage
@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 ChannelMessage) { messageListeners = listenerMap.get(((ChannelMessage) message).getChannelInt()); if (messageListeners != null) { for (MessageListener listener : messageListeners) { listener.messageReceived(message); } } } // Then send the message to any listeners registered to all channels // or to listeners for messages that do not support channels. messageListeners = listenerMap.get(null); if (messageListeners != null) { for (MessageListener listener : messageListeners) { listener.messageReceived(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 ChannelMessage) { messageListeners = listenerMap.get(((ChannelMessage) message).getChannelInt()); if (messageListeners != null) { for (MessageListener listener : messageListeners) { listener.messageReceived(message); } } } // Then send the message to any listeners registered to all channels // or to listeners for messages that do not support channels. messageListeners = listenerMap.get(null); if (messageListeners != null) { for (MessageListener listener : messageListeners) { listener.messageReceived(message); } } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "void", "dispatchMessage", "(", "ArrayListMultimap", "<", "Integer", ",", "MessageListener", ">", "listenerMap", ",", "Message", "message", ")", "{", "List", "<", "MessageListener", ">", "messageListener...
Dispatch a message to the corresponding listener arrays in the listener map @param listenerMap ArrayListMultimap of listener arrays to dispatch the message to @param message Message to be dispatched to the listeners
[ "Dispatch", "a", "message", "to", "the", "corresponding", "listener", "arrays", "in", "the", "listener", "map" ]
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Firmata.java#L615-L637
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Parser/CommandParser.java
CommandParser.handleInputStream
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 firmataCommandByte = commandByte < (byte) 0xF0 ? (byte) (commandByte & 0xF0) : commandByte; MessageBuilder messageBuilder = messageBuilderMap.get(firmataCommandByte); if (messageBuilder != null) { // Pull out the pin identifier bits that were padded into the byte (if any) byte channelByte = (byte) (commandByte & 0x0F); Message message = messageBuilder.buildMessage(channelByte, inputStream); if (message == null) { log.error("Error building Firmata messageBuilder for command byte {}.", FirmataHelper.bytesToHexString(commandByte)); } else { return message; } } else { log.warn("Dropped byte {}.", FirmataHelper.bytesToHexString(commandByte)); } return null; }
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 firmataCommandByte = commandByte < (byte) 0xF0 ? (byte) (commandByte & 0xF0) : commandByte; MessageBuilder messageBuilder = messageBuilderMap.get(firmataCommandByte); if (messageBuilder != null) { // Pull out the pin identifier bits that were padded into the byte (if any) byte channelByte = (byte) (commandByte & 0x0F); Message message = messageBuilder.buildMessage(channelByte, inputStream); if (message == null) { log.error("Error building Firmata messageBuilder for command byte {}.", FirmataHelper.bytesToHexString(commandByte)); } else { return message; } } else { log.warn("Dropped byte {}.", FirmataHelper.bytesToHexString(commandByte)); } return null; }
[ "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...
Attempts to identify the corresponding Firmata Message object that responds to the given commandByte If found, it will ask for the message to be built using given inputStream. The builder will take away any bytes necessary to build the message and then return. To attempt to identify the correct message we must mask the incoming byte against 0xF0 if the byte is less than 0xF0, as commands below 0xF0 are only legal within this mask, due to potential data padding in the same byte, per the Firmata spec. @param commandByte CommandByte representing the identify of a specific command Message packet. @param inputStream InputStream representing the data following the command byte. @return Message representing the Firmata Message that the SerialPort communications device sent.
[ "Attempts", "to", "identify", "the", "corresponding", "Firmata", "Message", "object", "that", "responds", "to", "the", "given", "commandByte", "If", "found", "it", "will", "ask", "for", "the", "message", "to", "be", "built", "using", "given", "inputStream", "....
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Parser/CommandParser.java#L126-L147
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/SynchronousMessageListener.java
SynchronousMessageListener.messageReceived
@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!"); } } responseMessage = message; responseReceived = true; synchronized (lock) { lock.notify(); } }
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!"); } } responseMessage = message; responseReceived = true; synchronized (lock) { lock.notify(); } }
[ "@", "Override", "public", "void", "messageReceived", "(", "T", "message", ")", "{", "if", "(", "responseReceived", "!=", "null", ")", "{", "if", "(", "responseReceived", ")", "{", "log", ".", "warn", "(", "\"Received more than one synchronous message reply!\"", ...
When we get our expected message response. Save the message object, and notify the waiting thread that the message is now available to be passed back. This method attempts to handle and warn against cases where multiple messages came in, or a message came in after the timeout period. @param message Message response from the project board that will be saved.
[ "When", "we", "get", "our", "expected", "message", "response", ".", "Save", "the", "message", "object", "and", "notify", "the", "waiting", "thread", "that", "the", "message", "is", "now", "available", "to", "be", "passed", "back", ".", "This", "method", "a...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/SynchronousMessageListener.java#L35-L52
train
reapzor/FiloFirmata
src/main/java/com/bortbort/arduino/FiloFirmata/Parser/SysexCommandParser.java
SysexCommandParser.buildMessage
@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; } ByteArrayOutputStream messageBodyBuilder = new ByteArrayOutputStream(16); try { int messagePiece; while ((messagePiece = inputStream.read()) != -1) { if ((byte) messagePiece == CommandBytes.END_SYSEX.getCommandByte()) { break; } messageBodyBuilder.write(messagePiece); } } catch (IOException e) { log.error("Error reading Sysex message body for command {}.", FirmataHelper.bytesToHexString(sysexCommandByte)); return null; } byte[] messageBodyBytes = messageBodyBuilder.toByteArray(); try { messageBodyBuilder.close(); } catch (IOException e) { log.error("Programming error. Cannot close our byte buffer."); } SysexMessageBuilder messageBuilder = messageBuilderMap.get(sysexCommandByte); if (messageBuilder == null) { log.error("There is no Sysex message parser registered for command {}. Body: {}", FirmataHelper.bytesToHexString(sysexCommandByte), FirmataHelper.bytesToHexString(messageBodyBuilder.toByteArray())); return null; } return messageBuilder.buildMessage(messageBodyBytes); }
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; } ByteArrayOutputStream messageBodyBuilder = new ByteArrayOutputStream(16); try { int messagePiece; while ((messagePiece = inputStream.read()) != -1) { if ((byte) messagePiece == CommandBytes.END_SYSEX.getCommandByte()) { break; } messageBodyBuilder.write(messagePiece); } } catch (IOException e) { log.error("Error reading Sysex message body for command {}.", FirmataHelper.bytesToHexString(sysexCommandByte)); return null; } byte[] messageBodyBytes = messageBodyBuilder.toByteArray(); try { messageBodyBuilder.close(); } catch (IOException e) { log.error("Programming error. Cannot close our byte buffer."); } SysexMessageBuilder messageBuilder = messageBuilderMap.get(sysexCommandByte); if (messageBuilder == null) { log.error("There is no Sysex message parser registered for command {}. Body: {}", FirmataHelper.bytesToHexString(sysexCommandByte), FirmataHelper.bytesToHexString(messageBodyBuilder.toByteArray())); return null; } return messageBuilder.buildMessage(messageBodyBytes); }
[ "@", "Override", "public", "Message", "buildMessage", "(", "Byte", "channelByte", ",", "InputStream", "inputStream", ")", "{", "byte", "sysexCommandByte", ";", "try", "{", "sysexCommandByte", "=", "(", "byte", ")", "inputStream", ".", "read", "(", ")", ";", ...
Attempts to identify the corresponding Firmata Sysex Message object that responds to the identified sysexCommandByte. If found, it will ask for the sysex message to be built using the identified bytes between the sysexCommandByte and the END_SYSEX commandByte later in the input stream. @param channelByte channelByte indicating the pin/port to perform the command against. @param inputStream InputStream representing the data following the START_SYSEX command byte. @return Message representing the Firmata Sysex Message that the SerialPort communications device sent.
[ "Attempts", "to", "identify", "the", "corresponding", "Firmata", "Sysex", "Message", "object", "that", "responds", "to", "the", "identified", "sysexCommandByte", ".", "If", "found", "it", "will", "ask", "for", "the", "sysex", "message", "to", "be", "built", "u...
39c26c1a577b8fff8690245e105cb62e02284f16
https://github.com/reapzor/FiloFirmata/blob/39c26c1a577b8fff8690245e105cb62e02284f16/src/main/java/com/bortbort/arduino/FiloFirmata/Parser/SysexCommandParser.java#L106-L148
train
StripesFramework/stripes-xss
src/main/java/com/samaxes/stripes/xss/SafeHtmlUtil.java
SafeHtmlUtil.sanitize
public static String sanitize(String raw) { return (raw == null || raw.length() == 0) ? raw : HTMLEntityEncode(canonicalize(raw)); }
java
public static String sanitize(String raw) { return (raw == null || raw.length() == 0) ? raw : HTMLEntityEncode(canonicalize(raw)); }
[ "public", "static", "String", "sanitize", "(", "String", "raw", ")", "{", "return", "(", "raw", "==", "null", "||", "raw", ".", "length", "(", ")", "==", "0", ")", "?", "raw", ":", "HTMLEntityEncode", "(", "canonicalize", "(", "raw", ")", ")", ";", ...
Sanitize user inputs. @param raw the input string to be sanitized @return the sanitized string
[ "Sanitize", "user", "inputs", "." ]
f78ba9eaa2a6cb4fc287dd3a250b9daaafc07ea6
https://github.com/StripesFramework/stripes-xss/blob/f78ba9eaa2a6cb4fc287dd3a250b9daaafc07ea6/src/main/java/com/samaxes/stripes/xss/SafeHtmlUtil.java#L40-L42
train
StripesFramework/stripes-xss
src/main/java/com/samaxes/stripes/xss/SafeHtmlUtil.java
SafeHtmlUtil.HTMLEntityEncode
public static String HTMLEntityEncode(String input) { String next = scriptPattern.matcher(input).replaceAll("&#x73;cript"); StringBuffer sb = new StringBuffer(); for (int i = 0; i < next.length(); ++i) { char ch = next.charAt(i); if (ch == '<') { sb.append("&lt;"); } else if (ch == '>') { sb.append("&gt;"); } else { sb.append(ch); } } return sb.toString(); }
java
public static String HTMLEntityEncode(String input) { String next = scriptPattern.matcher(input).replaceAll("&#x73;cript"); StringBuffer sb = new StringBuffer(); for (int i = 0; i < next.length(); ++i) { char ch = next.charAt(i); if (ch == '<') { sb.append("&lt;"); } else if (ch == '>') { sb.append("&gt;"); } else { sb.append(ch); } } return sb.toString(); }
[ "public", "static", "String", "HTMLEntityEncode", "(", "String", "input", ")", "{", "String", "next", "=", "scriptPattern", ".", "matcher", "(", "input", ")", ".", "replaceAll", "(", "\"&#x73;cript\"", ")", ";", "StringBuffer", "sb", "=", "new", "StringBuffer"...
Encode HTML entities. @param input the input string to be encoded @return the encoded string
[ "Encode", "HTML", "entities", "." ]
f78ba9eaa2a6cb4fc287dd3a250b9daaafc07ea6
https://github.com/StripesFramework/stripes-xss/blob/f78ba9eaa2a6cb4fc287dd3a250b9daaafc07ea6/src/main/java/com/samaxes/stripes/xss/SafeHtmlUtil.java#L50-L67
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputBatch.java
DefaultConnectionOutputBatch.checkEnd
private void checkEnd() { if (ended && !closed && children == 0) { closed = true; connection.doBatchEnd(id, endArgs); if (endHandler != null) { endHandler.handle((Void) null); } } }
java
private void checkEnd() { if (ended && !closed && children == 0) { closed = true; connection.doBatchEnd(id, endArgs); if (endHandler != null) { endHandler.handle((Void) null); } } }
[ "private", "void", "checkEnd", "(", ")", "{", "if", "(", "ended", "&&", "!", "closed", "&&", "children", "==", "0", ")", "{", "closed", "=", "true", ";", "connection", ".", "doBatchEnd", "(", "id", ",", "endArgs", ")", ";", "if", "(", "endHandler", ...
Checks whether the batch is complete.
[ "Checks", "whether", "the", "batch", "is", "complete", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputBatch.java#L127-L135
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputBatch.java
DefaultConnectionOutputBatch.start
void start(Handler<ConnectionOutputBatch> startHandler) { connection.doBatchStart(id, args); this.startHandler = startHandler; }
java
void start(Handler<ConnectionOutputBatch> startHandler) { connection.doBatchStart(id, args); this.startHandler = startHandler; }
[ "void", "start", "(", "Handler", "<", "ConnectionOutputBatch", ">", "startHandler", ")", "{", "connection", ".", "doBatchStart", "(", "id", ",", "args", ")", ";", "this", ".", "startHandler", "=", "startHandler", ";", "}" ]
Starts the output batch.
[ "Starts", "the", "output", "batch", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputBatch.java#L147-L150
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/ModuleFields.java
ModuleFields.getInPorts
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 jsonInPort : jsonInPorts) { ports.add((String) jsonInPort); } return ports; }
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 jsonInPort : jsonInPorts) { ports.add((String) jsonInPort); } return ports; }
[ "public", "List", "<", "String", ">", "getInPorts", "(", ")", "{", "List", "<", "String", ">", "ports", "=", "new", "ArrayList", "<>", "(", ")", ";", "JsonObject", "jsonPorts", "=", "config", ".", "getObject", "(", "\"ports\"", ")", ";", "if", "(", "...
Returns a list of input ports defined by the module. @return A list of input ports defined by the module.
[ "Returns", "a", "list", "of", "input", "ports", "defined", "by", "the", "module", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/ModuleFields.java#L52-L66
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/ModuleFields.java
ModuleFields.getOutPorts
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 jsonOutPort : jsonOutPorts) { ports.add((String) jsonOutPort); } return ports; }
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 jsonOutPort : jsonOutPorts) { ports.add((String) jsonOutPort); } return ports; }
[ "public", "List", "<", "String", ">", "getOutPorts", "(", ")", "{", "List", "<", "String", ">", "ports", "=", "new", "ArrayList", "<>", "(", ")", ";", "JsonObject", "jsonPorts", "=", "config", ".", "getObject", "(", "\"ports\"", ")", ";", "if", "(", ...
Returns a list of output ports defined by the module. @return A list of output ports defined by the module.
[ "Returns", "a", "list", "of", "output", "ports", "defined", "by", "the", "module", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/ModuleFields.java#L73-L87
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java
CountingCompletionHandler.fail
public void fail(Throwable t) { if (!failed) { if (doneHandler != null) { doneHandler.handle(new DefaultFutureResult<T>(t)); } else { cause = t; } failed = true; } }
java
public void fail(Throwable t) { if (!failed) { if (doneHandler != null) { doneHandler.handle(new DefaultFutureResult<T>(t)); } else { cause = t; } failed = true; } }
[ "public", "void", "fail", "(", "Throwable", "t", ")", "{", "if", "(", "!", "failed", ")", "{", "if", "(", "doneHandler", "!=", "null", ")", "{", "doneHandler", ".", "handle", "(", "new", "DefaultFutureResult", "<", "T", ">", "(", "t", ")", ")", ";"...
Indicates that a call failed. This will immediately fail the handler. @param t The cause of the failure.
[ "Indicates", "that", "a", "call", "failed", ".", "This", "will", "immediately", "fail", "the", "handler", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java#L61-L70
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java
CountingCompletionHandler.setHandler
public CountingCompletionHandler<T> setHandler(Handler<AsyncResult<T>> doneHandler) { this.doneHandler = doneHandler; checkDone(); return this; }
java
public CountingCompletionHandler<T> setHandler(Handler<AsyncResult<T>> doneHandler) { this.doneHandler = doneHandler; checkDone(); return this; }
[ "public", "CountingCompletionHandler", "<", "T", ">", "setHandler", "(", "Handler", "<", "AsyncResult", "<", "T", ">", ">", "doneHandler", ")", "{", "this", ".", "doneHandler", "=", "doneHandler", ";", "checkDone", "(", ")", ";", "return", "this", ";", "}"...
Sets the completion handler. @param doneHandler An asynchronous handler to be called once all calls have completed.
[ "Sets", "the", "completion", "handler", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java#L77-L81
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java
CountingCompletionHandler.checkDone
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 checkDone() { if (doneHandler != null) { if (cause != null) { doneHandler.handle(new DefaultFutureResult<T>(cause)); } else { if (count == required) { doneHandler.handle(new DefaultFutureResult<T>((T) null)); } } } }
[ "private", "void", "checkDone", "(", ")", "{", "if", "(", "doneHandler", "!=", "null", ")", "{", "if", "(", "cause", "!=", "null", ")", "{", "doneHandler", ".", "handle", "(", "new", "DefaultFutureResult", "<", "T", ">", "(", "cause", ")", ")", ";", ...
Checks whether the handler should be called.
[ "Checks", "whether", "the", "handler", "should", "be", "called", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/CountingCompletionHandler.java#L86-L96
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/component/impl/DefaultComponent.java
DefaultComponent.setup
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.debug(String.format("%s - Starting cluster coordination", DefaultComponent.this)); coordinator.start(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { // We have to make sure the input and output collectors are started // simultaneously in order to support circular connections. If both // input and output aren't started at the same time then circular // connections will never open. final CountingCompletionHandler<Void> ioHandler = new CountingCompletionHandler<Void>(2); ioHandler.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { // Tell the coordinator we're ready for the network to start. coordinator.resume(); } } }); output.open(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(String.format("%s - Failed to open component outputs", DefaultComponent.this), result.cause()); ioHandler.fail(result.cause()); } else { ioHandler.succeed(); } } }); input.open(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(String.format("%s - Failed to open component inputs", DefaultComponent.this), result.cause()); ioHandler.fail(result.cause()); } else { ioHandler.succeed(); } } }); } } }); // The resume handler will be called by the coordinator once the // network's manager has indicated that all the components in the // network have finished setting up their connections. coordinator.resumeHandler(new Handler<Void>() { @Override @SuppressWarnings("unchecked") public void handle(Void _) { if (!started) { started = true; log.debug(String.format("%s - Started", DefaultComponent.this, context.component().name(), context.number())); List<ComponentHook> hooks = context.component().hooks(); for (ComponentHook hook : hooks) { hook.handleStart(DefaultComponent.this); } new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); }
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.debug(String.format("%s - Starting cluster coordination", DefaultComponent.this)); coordinator.start(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { // We have to make sure the input and output collectors are started // simultaneously in order to support circular connections. If both // input and output aren't started at the same time then circular // connections will never open. final CountingCompletionHandler<Void> ioHandler = new CountingCompletionHandler<Void>(2); ioHandler.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { // Tell the coordinator we're ready for the network to start. coordinator.resume(); } } }); output.open(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(String.format("%s - Failed to open component outputs", DefaultComponent.this), result.cause()); ioHandler.fail(result.cause()); } else { ioHandler.succeed(); } } }); input.open(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(String.format("%s - Failed to open component inputs", DefaultComponent.this), result.cause()); ioHandler.fail(result.cause()); } else { ioHandler.succeed(); } } }); } } }); // The resume handler will be called by the coordinator once the // network's manager has indicated that all the components in the // network have finished setting up their connections. coordinator.resumeHandler(new Handler<Void>() { @Override @SuppressWarnings("unchecked") public void handle(Void _) { if (!started) { started = true; log.debug(String.format("%s - Started", DefaultComponent.this, context.component().name(), context.number())); List<ComponentHook> hooks = context.component().hooks(); for (ComponentHook hook : hooks) { hook.handleStart(DefaultComponent.this); } new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); }
[ "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", "// ...
Sets up the component.
[ "Sets", "up", "the", "component", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/component/impl/DefaultComponent.java#L113-L186
train
kuujo/vertigo
util/src/main/java/net/kuujo/vertigo/io/Pump.java
Pump.start
public void start() { input.messageHandler(new Handler<Object>() { @Override public void handle(Object message) { output.send(message); pumped++; } }); }
java
public void start() { input.messageHandler(new Handler<Object>() { @Override public void handle(Object message) { output.send(message); pumped++; } }); }
[ "public", "void", "start", "(", ")", "{", "input", ".", "messageHandler", "(", "new", "Handler", "<", "Object", ">", "(", ")", "{", "@", "Override", "public", "void", "handle", "(", "Object", "message", ")", "{", "output", ".", "send", "(", "message", ...
Starts the pump.
[ "Starts", "the", "pump", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/util/src/main/java/net/kuujo/vertigo/io/Pump.java#L58-L66
train
kuujo/vertigo
util/src/main/java/net/kuujo/vertigo/io/Feeder.java
Feeder.createFeeder
public static <T extends Output<T>> Feeder<T> createFeeder(T output) { return new Feeder<T>(output); }
java
public static <T extends Output<T>> Feeder<T> createFeeder(T output) { return new Feeder<T>(output); }
[ "public", "static", "<", "T", "extends", "Output", "<", "T", ">", ">", "Feeder", "<", "T", ">", "createFeeder", "(", "T", "output", ")", "{", "return", "new", "Feeder", "<", "T", ">", "(", "output", ")", ";", "}" ]
Creates a new feeder. @param output The output to which to feed messages. @return A new feeder.
[ "Creates", "a", "new", "feeder", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/util/src/main/java/net/kuujo/vertigo/io/Feeder.java#L63-L65
train
kuujo/vertigo
util/src/main/java/net/kuujo/vertigo/io/Feeder.java
Feeder.doFeed
private void doFeed() { if (fed && !output.sendQueueFull()) { fed = false; vertx.runOnContext(feedRunner); } else { feedTimer = vertx.setTimer(feedDelay, recursiveRunner); } }
java
private void doFeed() { if (fed && !output.sendQueueFull()) { fed = false; vertx.runOnContext(feedRunner); } else { feedTimer = vertx.setTimer(feedDelay, recursiveRunner); } }
[ "private", "void", "doFeed", "(", ")", "{", "if", "(", "fed", "&&", "!", "output", ".", "sendQueueFull", "(", ")", ")", "{", "fed", "=", "false", ";", "vertx", ".", "runOnContext", "(", "feedRunner", ")", ";", "}", "else", "{", "feedTimer", "=", "v...
Feeds the next message.
[ "Feeds", "the", "next", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/util/src/main/java/net/kuujo/vertigo/io/Feeder.java#L115-L122
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Components.java
Components.createComponent
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, container)); }
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, container)); }
[ "public", "static", "Component", "createComponent", "(", "Vertx", "vertx", ",", "Container", "container", ")", "{", "InstanceContext", "context", "=", "parseContext", "(", "container", ".", "config", "(", ")", ")", ";", "return", "new", "DefaultComponentFactory", ...
Creates a component instance for the current Vert.x instance.
[ "Creates", "a", "component", "instance", "for", "the", "current", "Vert", ".", "x", "instance", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Components.java#L74-L77
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Components.java
Components.buildConfig
public static JsonObject buildConfig(InstanceContext context, Cluster cluster) { JsonObject config = context.component().config().copy(); return config.putObject("__context__", Contexts.serialize(context)); }
java
public static JsonObject buildConfig(InstanceContext context, Cluster cluster) { JsonObject config = context.component().config().copy(); return config.putObject("__context__", Contexts.serialize(context)); }
[ "public", "static", "JsonObject", "buildConfig", "(", "InstanceContext", "context", ",", "Cluster", "cluster", ")", "{", "JsonObject", "config", "=", "context", ".", "component", "(", ")", ".", "config", "(", ")", ".", "copy", "(", ")", ";", "return", "con...
Builds a verticle configuration. @param context The verticle context. @return A verticle configuration.
[ "Builds", "a", "verticle", "configuration", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Components.java#L85-L88
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Components.java
Components.parseContext
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 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); }
[ "private", "static", "InstanceContext", "parseContext", "(", "JsonObject", "config", ")", "{", "JsonObject", "context", "=", "config", ".", "getObject", "(", "\"__context__\"", ")", ";", "if", "(", "context", "==", "null", ")", "{", "throw", "new", "IllegalArg...
Parses an instance context from configuration. @param config The verticle configuration. @return The verticle context.
[ "Parses", "an", "instance", "context", "from", "configuration", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Components.java#L96-L103
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.locateModules
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 { new ModuleIdentifier(file.getName()); } catch (Exception e) { isValid = false; } // If the directory is a valid module name then check for a mod.json file. if (isValid) { File modJson = new File(file, MOD_JSON_FILE); if (modJson.exists()) { modFiles.add(file); } } } } return modFiles; }
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 { new ModuleIdentifier(file.getName()); } catch (Exception e) { isValid = false; } // If the directory is a valid module name then check for a mod.json file. if (isValid) { File modJson = new File(file, MOD_JSON_FILE); if (modJson.exists()) { modFiles.add(file); } } } } return modFiles; }
[ "private", "List", "<", "File", ">", "locateModules", "(", ")", "{", "File", "[", "]", "files", "=", "modRoot", ".", "listFiles", "(", ")", ";", "List", "<", "File", ">", "modFiles", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "File",...
Locates all modules in the local repository.
[ "Locates", "all", "modules", "in", "the", "local", "repository", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L206-L229
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.locateModule
private File locateModule(ModuleIdentifier modID) { File modDir = new File(modRoot, modID.toString()); if (modDir.exists()) { return modDir; } return null; }
java
private File locateModule(ModuleIdentifier modID) { File modDir = new File(modRoot, modID.toString()); if (modDir.exists()) { return modDir; } return null; }
[ "private", "File", "locateModule", "(", "ModuleIdentifier", "modID", ")", "{", "File", "modDir", "=", "new", "File", "(", "modRoot", ",", "modID", ".", "toString", "(", ")", ")", ";", "if", "(", "modDir", ".", "exists", "(", ")", ")", "{", "return", ...
Locates a module in the modules root directory.
[ "Locates", "a", "module", "in", "the", "modules", "root", "directory", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L234-L240
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.pullInDependencies
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. ModuleFields fields = info.fields(); List<String> mods = new ArrayList<>(); // Add "includes" modules. String sincludes = fields.getIncludes(); if (sincludes != null) { String[] includes = parseIncludes(sincludes); if (includes != null) { mods.addAll(Arrays.asList(includes)); } } // Add "deploys" modules. String sdeploys = fields.getDeploys(); if (sdeploys != null) { String[] deploys = parseIncludes(sdeploys); if (deploys != null) { mods.addAll(Arrays.asList(deploys)); } } // Iterate through "includes" and "deploys" and attempt to move them // into the module directory if they can be found. Note that this // requires that the modules be installed. It does not check remote // repositories since it's assumed that remote repositories can be // access from any node to which the module goes. if (!mods.isEmpty()) { File internalModsDir = new File(modDir, "mods"); if (!internalModsDir.exists()) { if (!internalModsDir.mkdir()) { throw new PlatformManagerException("Failed to create directory " + internalModsDir); } } for (String moduleName : mods) { File internalModDir = new File(internalModsDir, moduleName); if (!internalModDir.exists()) { ModuleIdentifier childModID = new ModuleIdentifier(moduleName); File includeModDir = locateModule(childModID); if (includeModDir != null) { vertx.fileSystem().copySync(includeModDir.getAbsolutePath(), internalModDir.getAbsolutePath(), true); pullInDependencies(childModID, internalModDir); } } } } }
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. ModuleFields fields = info.fields(); List<String> mods = new ArrayList<>(); // Add "includes" modules. String sincludes = fields.getIncludes(); if (sincludes != null) { String[] includes = parseIncludes(sincludes); if (includes != null) { mods.addAll(Arrays.asList(includes)); } } // Add "deploys" modules. String sdeploys = fields.getDeploys(); if (sdeploys != null) { String[] deploys = parseIncludes(sdeploys); if (deploys != null) { mods.addAll(Arrays.asList(deploys)); } } // Iterate through "includes" and "deploys" and attempt to move them // into the module directory if they can be found. Note that this // requires that the modules be installed. It does not check remote // repositories since it's assumed that remote repositories can be // access from any node to which the module goes. if (!mods.isEmpty()) { File internalModsDir = new File(modDir, "mods"); if (!internalModsDir.exists()) { if (!internalModsDir.mkdir()) { throw new PlatformManagerException("Failed to create directory " + internalModsDir); } } for (String moduleName : mods) { File internalModDir = new File(internalModsDir, moduleName); if (!internalModDir.exists()) { ModuleIdentifier childModID = new ModuleIdentifier(moduleName); File includeModDir = locateModule(childModID); if (includeModDir != null) { vertx.fileSystem().copySync(includeModDir.getAbsolutePath(), internalModDir.getAbsolutePath(), true); pullInDependencies(childModID, internalModDir); } } } } }
[ "private", "void", "pullInDependencies", "(", "ModuleIdentifier", "modID", ",", "File", "modDir", ")", "{", "// Load the module configuration file.", "File", "modJsonFile", "=", "new", "File", "(", "modDir", ",", "MOD_JSON_FILE", ")", ";", "ModuleInfo", "info", "=",...
Pulls in all dependencies for a module.
[ "Pulls", "in", "all", "dependencies", "for", "a", "module", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L267-L319
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.zipModule
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(TEMP_DIR, "vertx-zip-mods"); // Create a zip file. If the zip file already exists in the temporary // Vertigo zips directory then just return the existing zip file. File zipFile = new File(modRoot, modID.toString() + ".zip"); if (zipFile.exists()) { return zipFile; } // Create a temporary directory to which we'll copy the module and its dependencies. File modDest = new File(modRoot, modID.toString() + "-" + UUID.randomUUID().toString()); File modHome = new File(modDest, modID.toString()); // Create the temporary destination directory. vertx.fileSystem().mkdirSync(modHome.getAbsolutePath(), true); // Copy the module into the temporary directory. vertx.fileSystem().copySync(modDir.getAbsolutePath(), modHome.getAbsolutePath(), true); // Pull any module dependencies ("includes" and "deploys") into the temporary directory. pullInDependencies(modID, modHome); // Zip up the temporary directory into the zip file. zipDirectory(zipFile.getPath(), modDest.getAbsolutePath()); // Delete the temporary directory. vertx.fileSystem().deleteSync(modDest.getAbsolutePath(), true); return zipFile; }
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(TEMP_DIR, "vertx-zip-mods"); // Create a zip file. If the zip file already exists in the temporary // Vertigo zips directory then just return the existing zip file. File zipFile = new File(modRoot, modID.toString() + ".zip"); if (zipFile.exists()) { return zipFile; } // Create a temporary directory to which we'll copy the module and its dependencies. File modDest = new File(modRoot, modID.toString() + "-" + UUID.randomUUID().toString()); File modHome = new File(modDest, modID.toString()); // Create the temporary destination directory. vertx.fileSystem().mkdirSync(modHome.getAbsolutePath(), true); // Copy the module into the temporary directory. vertx.fileSystem().copySync(modDir.getAbsolutePath(), modHome.getAbsolutePath(), true); // Pull any module dependencies ("includes" and "deploys") into the temporary directory. pullInDependencies(modID, modHome); // Zip up the temporary directory into the zip file. zipDirectory(zipFile.getPath(), modDest.getAbsolutePath()); // Delete the temporary directory. vertx.fileSystem().deleteSync(modDest.getAbsolutePath(), true); return zipFile; }
[ "private", "File", "zipModule", "(", "ModuleIdentifier", "modID", ")", "{", "File", "modDir", "=", "new", "File", "(", "modRoot", ",", "modID", ".", "toString", "(", ")", ")", ";", "if", "(", "!", "modDir", ".", "exists", "(", ")", ")", "{", "throw",...
Creates a zip file from a module.
[ "Creates", "a", "zip", "file", "from", "a", "module", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L324-L359
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.zipDirectory
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("Failed to zip module", e); } }
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("Failed to zip module", e); } }
[ "private", "void", "zipDirectory", "(", "String", "zipFile", ",", "String", "dirToZip", ")", "{", "File", "directory", "=", "new", "File", "(", "dirToZip", ")", ";", "try", "(", "ZipOutputStream", "stream", "=", "new", "ZipOutputStream", "(", "new", "FileOut...
Zips up a directory.
[ "Zips", "up", "a", "directory", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L364-L371
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.addDirectoryToZip
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 = Paths.get(files[i].getAbsolutePath()); Path relative = top.relativize(entry); String entryName = relative.toString(); if (files[i].isDirectory()) { entryName += FILE_SEPARATOR; } out.putNextEntry(new ZipEntry(entryName.replace("\\", "/"))); if (!files[i].isDirectory()) { try (FileInputStream in = new FileInputStream(files[i])) { int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } out.closeEntry(); } if (files[i].isDirectory()) { addDirectoryToZip(topDirectory, files[i], out); } } }
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 = Paths.get(files[i].getAbsolutePath()); Path relative = top.relativize(entry); String entryName = relative.toString(); if (files[i].isDirectory()) { entryName += FILE_SEPARATOR; } out.putNextEntry(new ZipEntry(entryName.replace("\\", "/"))); if (!files[i].isDirectory()) { try (FileInputStream in = new FileInputStream(files[i])) { int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } out.closeEntry(); } if (files[i].isDirectory()) { addDirectoryToZip(topDirectory, files[i], out); } } }
[ "private", "void", "addDirectoryToZip", "(", "File", "topDirectory", ",", "File", "directory", ",", "ZipOutputStream", "out", ")", "throws", "IOException", "{", "Path", "top", "=", "Paths", ".", "get", "(", "topDirectory", ".", "getAbsolutePath", "(", ")", ")"...
Recursively adds directories to a zip file.
[ "Recursively", "adds", "directories", "to", "a", "zip", "file", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L376-L406
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.parseIncludes
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 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; }
[ "private", "String", "[", "]", "parseIncludes", "(", "String", "sincludes", ")", "{", "sincludes", "=", "sincludes", ".", "trim", "(", ")", ";", "if", "(", "\"\"", ".", "equals", "(", "sincludes", ")", ")", "{", "return", "null", ";", "}", "String", ...
Parses an includes string.
[ "Parses", "an", "includes", "string", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L411-L423
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java
DefaultPlatformManager.unzipModuleData
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) { String entryName = entry.getName(); if (!entryName.isEmpty()) { if (entry.isDirectory()) { File dir = new File(directory, entryName); if (!dir.exists()) { if (!new File(directory, entryName).mkdir()) { throw new PlatformManagerException("Failed to create directory"); } } } else { int count; byte[] buffer = new byte[BUFFER_SIZE]; BufferedOutputStream out = null; try { OutputStream os = new FileOutputStream(new File(directory, entryName)); out = new BufferedOutputStream(os, BUFFER_SIZE); while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1) { out.write(buffer, 0, count); } out.flush(); } finally { if (out != null) { out.close(); } } } } } } catch (Exception e) { throw new PlatformManagerException("Failed to unzip module", e); } finally { if (deleteZip) { zipFile.delete(); } } }
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) { String entryName = entry.getName(); if (!entryName.isEmpty()) { if (entry.isDirectory()) { File dir = new File(directory, entryName); if (!dir.exists()) { if (!new File(directory, entryName).mkdir()) { throw new PlatformManagerException("Failed to create directory"); } } } else { int count; byte[] buffer = new byte[BUFFER_SIZE]; BufferedOutputStream out = null; try { OutputStream os = new FileOutputStream(new File(directory, entryName)); out = new BufferedOutputStream(os, BUFFER_SIZE); while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1) { out.write(buffer, 0, count); } out.flush(); } finally { if (out != null) { out.close(); } } } } } } catch (Exception e) { throw new PlatformManagerException("Failed to unzip module", e); } finally { if (deleteZip) { zipFile.delete(); } } }
[ "private", "void", "unzipModuleData", "(", "File", "directory", ",", "File", "zipFile", ",", "boolean", "deleteZip", ")", "{", "try", "(", "InputStream", "in", "=", "new", "BufferedInputStream", "(", "new", "FileInputStream", "(", "zipFile", ")", ")", ";", "...
Unzips a module.
[ "Unzips", "a", "module", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/platform/impl/DefaultPlatformManager.java#L436-L475
train
lordcodes/SnackbarBuilder
snackbarbuilder/src/main/java/com/github/andrewlord1990/snackbarbuilder/toastbuilder/ToastBuilder.java
ToastBuilder.build
@SuppressLint("ShowToast") public Toast build() { Toast toast = Toast.makeText(context, message, duration); TextView toastMessage = setupToastView(toast); setToastMessageTextColor(toastMessage); setToastGravity(toast); return toast; }
java
@SuppressLint("ShowToast") public Toast build() { Toast toast = Toast.makeText(context, message, duration); TextView toastMessage = setupToastView(toast); setToastMessageTextColor(toastMessage); setToastGravity(toast); return toast; }
[ "@", "SuppressLint", "(", "\"ShowToast\"", ")", "public", "Toast", "build", "(", ")", "{", "Toast", "toast", "=", "Toast", ".", "makeText", "(", "context", ",", "message", ",", "duration", ")", ";", "TextView", "toastMessage", "=", "setupToastView", "(", "...
Build a Toast using the options specified in the builder. @return The constructed Toast.
[ "Build", "a", "Toast", "using", "the", "options", "specified", "in", "the", "builder", "." ]
a104a753c78ed66940c19d295e141a521cf81d73
https://github.com/lordcodes/SnackbarBuilder/blob/a104a753c78ed66940c19d295e141a521cf81d73/snackbarbuilder/src/main/java/com/github/andrewlord1990/snackbarbuilder/toastbuilder/ToastBuilder.java#L174-L183
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.handleCreate
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>() { @Override public void handle(final Task task) { currentContext = context; // Any time the network is being reconfigured, unready the network. // This will cause components to pause during the reconfiguration. unready(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); task.complete(); } else { deployNetwork(context, new Handler<AsyncResult<NetworkContext>>() { @Override public void handle(AsyncResult<NetworkContext> result) { task.complete(); if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully deployed network", NetworkManager.this)); } } }); } } }); } }); }
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>() { @Override public void handle(final Task task) { currentContext = context; // Any time the network is being reconfigured, unready the network. // This will cause components to pause during the reconfiguration. unready(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); task.complete(); } else { deployNetwork(context, new Handler<AsyncResult<NetworkContext>>() { @Override public void handle(AsyncResult<NetworkContext> result) { task.complete(); if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully deployed network", NetworkManager.this)); } } }); } } }); } }); }
[ "private", "void", "handleCreate", "(", "final", "NetworkContext", "context", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Network configuration created in cluster: %s\"", ",", "NetworkManager", ".", "this", ",", "cluster", ".", "address...
Handles the creation of the network.
[ "Handles", "the", "creation", "of", "the", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L255-L288
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.undeployRemovedComponents
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 (ComponentContext<?> runningComponent : runningContext.components()) { if (context.component(runningComponent.name()) == null) { removedComponents.add(runningComponent); } } if (!removedComponents.isEmpty()) { final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(removedComponents.size()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { log.info(String.format("%s - Removed %d components", NetworkManager.this, removedComponents.size())); new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); undeployComponents(removedComponents, counter); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } }
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 (ComponentContext<?> runningComponent : runningContext.components()) { if (context.component(runningComponent.name()) == null) { removedComponents.add(runningComponent); } } if (!removedComponents.isEmpty()) { final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(removedComponents.size()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { log.info(String.format("%s - Removed %d components", NetworkManager.this, removedComponents.size())); new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); undeployComponents(removedComponents, counter); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } }
[ "private", "void", "undeployRemovedComponents", "(", "final", "NetworkContext", "context", ",", "final", "NetworkContext", "runningContext", ",", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "// Undeploy any components that wer...
Undeploys components that were removed from the network.
[ "Undeploys", "components", "that", "were", "removed", "from", "the", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L375-L401
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.handleDelete
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>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); } if (currentContext != null) { log.info(String.format("%s - Undeploying network", NetworkManager.this)); undeployNetwork(currentContext, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); task.complete(); } else { // Once we've finished undeploying all the components of the // network, set the network's status to nothing in order to // indicate that the manager (this) can be undeployed. data.put(currentContext.status(), "", new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully undeployed all components", NetworkManager.this)); } task.complete(); } }); } } }); } else { task.complete(); } } }); } }); }
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>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); } if (currentContext != null) { log.info(String.format("%s - Undeploying network", NetworkManager.this)); undeployNetwork(currentContext, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); task.complete(); } else { // Once we've finished undeploying all the components of the // network, set the network's status to nothing in order to // indicate that the manager (this) can be undeployed. data.put(currentContext.status(), "", new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully undeployed all components", NetworkManager.this)); } task.complete(); } }); } } }); } else { task.complete(); } } }); } }); }
[ "private", "void", "handleDelete", "(", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Network configuration removed from cluster: %s\"", ",", "NetworkManager", ".", "this", ",", "cluster", ".", "address", "(", ")", ")", ")", ";", "t...
Handles the deletion of the network.
[ "Handles", "the", "deletion", "of", "the", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L436-L480
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.unready
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(AsyncResult<String> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); } }
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(AsyncResult<String> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); } }
[ "private", "void", "unready", "(", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "if", "(", "currentContext", "!=", "null", "&&", "data", "!=", "null", ")", "{", "log", ".", "debug", "(", "String", ".", "format...
Unreadies the network.
[ "Unreadies", "the", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L485-L499
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.handleReady
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 handleReady(String address) { log.debug(String.format("%s - Received ready message from %s", NetworkManager.this, address)); ready.add(address); checkReady(); }
[ "private", "void", "handleReady", "(", "String", "address", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Received ready message from %s\"", ",", "NetworkManager", ".", "this", ",", "address", ")", ")", ";", "ready", ".", "add", "...
Called when a component instance is ready.
[ "Called", "when", "a", "component", "instance", "is", "ready", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L504-L508
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.checkReady
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 complete. data.put(currentContext.status(), currentContext.version(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { log.error(result.cause()); } } }); } }
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 complete. data.put(currentContext.status(), currentContext.version(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { log.error(result.cause()); } } }); } }
[ "private", "void", "checkReady", "(", ")", "{", "if", "(", "allReady", "(", ")", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - All components ready in network, starting components\"", ",", "NetworkManager", ".", "this", ")", ")", ";...
Checks whether the network is ready.
[ "Checks", "whether", "the", "network", "is", "ready", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L513-L527
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.handleUnready
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 handleUnready(String address) { log.debug(String.format("%s - Received unready message from: %s", NetworkManager.this, address)); ready.remove(address); checkUnready(); }
[ "private", "void", "handleUnready", "(", "String", "address", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Received unready message from: %s\"", ",", "NetworkManager", ".", "this", ",", "address", ")", ")", ";", "ready", ".", "remo...
Called when a component instance is unready.
[ "Called", "when", "a", "component", "instance", "is", "unready", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L532-L536
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.checkUnready
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) { if (result.failed()) { log.error(result.cause()); } } }); } }
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) { if (result.failed()) { log.error(result.cause()); } } }); } }
[ "private", "void", "checkUnready", "(", ")", "{", "if", "(", "!", "allReady", "(", ")", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Components not ready, pausing components\"", ",", "NetworkManager", ".", "this", ")", ")", ";", ...
Checks whether the network is unready.
[ "Checks", "whether", "the", "network", "is", "unready", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L541-L553
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.allReady
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 : component.instances()) { if (!ready.contains(instance.address())) { match = false; break outer; } } } return match; }
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 : component.instances()) { if (!ready.contains(instance.address())) { match = false; break outer; } } } return match; }
[ "private", "boolean", "allReady", "(", ")", "{", "if", "(", "currentContext", "==", "null", ")", "return", "false", ";", "List", "<", "InstanceContext", ">", "instances", "=", "new", "ArrayList", "<>", "(", ")", ";", "boolean", "match", "=", "true", ";",...
Checks whether all components are ready in the network.
[ "Checks", "whether", "all", "components", "are", "ready", "in", "the", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L558-L572
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployNetwork
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()); complete.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<NetworkContext>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<NetworkContext>(context).setHandler(doneHandler); } } }); deployComponents(context.components(), complete); }
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()); complete.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<NetworkContext>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<NetworkContext>(context).setHandler(doneHandler); } } }); deployComponents(context.components(), complete); }
[ "private", "void", "deployNetwork", "(", "final", "NetworkContext", "context", ",", "final", "Handler", "<", "AsyncResult", "<", "NetworkContext", ">", ">", "doneHandler", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Deploying networ...
Deploys a complete network.
[ "Deploys", "a", "complete", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L577-L591
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployComponents
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> result) { if (result.failed()) { counter.fail(result.cause()); } else { data.put(component.address(), Contexts.serialize(component).encode(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } } }); } }
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> result) { if (result.failed()) { counter.fail(result.cause()); } else { data.put(component.address(), Contexts.serialize(component).encode(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } } }); } }
[ "private", "void", "deployComponents", "(", "Collection", "<", "ComponentContext", "<", "?", ">", ">", "components", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "for", "(", "final", "ComponentContext", "<", "?", ">", "comp...
Deploys all network components.
[ "Deploys", "all", "network", "components", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L596-L618
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployInstances
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 deploying the instance, check if the instance is already deployed in // the network's cluster. deploymentIDs.get(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else if (result.result() == null) { // If no deployment ID has been assigned to the instance then that means it hasn't // yet been deployed. Deploy the instance. deployInstance(instance, counter); } else { // Even if the instance is already deployed, update its context in the cluster. // It's possible that the instance's connections could have changed with the update. data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } } }); } }
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 deploying the instance, check if the instance is already deployed in // the network's cluster. deploymentIDs.get(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else if (result.result() == null) { // If no deployment ID has been assigned to the instance then that means it hasn't // yet been deployed. Deploy the instance. deployInstance(instance, counter); } else { // Even if the instance is already deployed, update its context in the cluster. // It's possible that the instance's connections could have changed with the update. data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } } }); } }
[ "private", "void", "deployInstances", "(", "List", "<", "InstanceContext", ">", "instances", ",", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", "=", "n...
Deploys all network component instances.
[ "Deploys", "all", "network", "component", "instances", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L700-L731
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployInstance
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 (instance.component().group() != null) { cluster.getGroup(instance.component().group(), new Handler<AsyncResult<Group>>() { @Override public void handle(AsyncResult<Group> result) { if (result.failed()) { counter.fail(result.cause()); } else { result.result().selectNode(instance.address(), new Handler<AsyncResult<Node>>() { @Override public void handle(AsyncResult<Node> result) { if (result.failed()) { counter.fail(result.cause()); } else { deployInstance(result.result(), instance, counter); } } }); } } }); } else { cluster.selectNode(instance.address(), new Handler<AsyncResult<Node>>() { @Override public void handle(AsyncResult<Node> result) { if (result.failed()) { counter.fail(result.cause()); } else { deployInstance(result.result(), instance, counter); } } }); } }
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 (instance.component().group() != null) { cluster.getGroup(instance.component().group(), new Handler<AsyncResult<Group>>() { @Override public void handle(AsyncResult<Group> result) { if (result.failed()) { counter.fail(result.cause()); } else { result.result().selectNode(instance.address(), new Handler<AsyncResult<Node>>() { @Override public void handle(AsyncResult<Node> result) { if (result.failed()) { counter.fail(result.cause()); } else { deployInstance(result.result(), instance, counter); } } }); } } }); } else { cluster.selectNode(instance.address(), new Handler<AsyncResult<Node>>() { @Override public void handle(AsyncResult<Node> result) { if (result.failed()) { counter.fail(result.cause()); } else { deployInstance(result.result(), instance, counter); } } }); } }
[ "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.", "...
Deploys a single component instance.
[ "Deploys", "a", "single", "component", "instance", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L736-L772
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployInstance
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 (result.failed()) { counter.fail(result.cause()); } else { if (!watchHandlers.containsKey(instance.address())) { final Handler<MapEvent<String, String>> watchHandler = new Handler<MapEvent<String, String>>() { @Override public void handle(MapEvent<String, String> event) { if (event.type().equals(MapEvent.Type.CREATE) || event.type().equals(MapEvent.Type.UPDATE)) { handleReady(instance.address()); } else if (event.type().equals(MapEvent.Type.DELETE)) { handleUnready(instance.address()); } } }; // Watch the instance's status for changes. Once the instance has started // up, the component coordinator will set the instance's status key in the // cluster, indicating that the instance has completed started. Once all // instances in the network have completed startup the network will be started. data.watch(instance.status(), watchHandler, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { counter.fail(result.cause()); } else { watchHandlers.put(instance.address(), watchHandler); if (instance.component().isModule()) { deployModule(node, instance, counter); } else if (instance.component().isVerticle() && !instance.component().asVerticle().isWorker()) { deployVerticle(node, instance, counter); } else if (instance.component().isVerticle() && instance.component().asVerticle().isWorker()) { deployWorkerVerticle(node, instance, counter); } } } }); } else { if (instance.component().isModule()) { deployModule(node, instance, counter); } else if (instance.component().isVerticle() && !instance.component().asVerticle().isWorker()) { deployVerticle(node, instance, counter); } else if (instance.component().isVerticle() && instance.component().asVerticle().isWorker()) { deployWorkerVerticle(node, instance, counter); } } } } }); }
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 (result.failed()) { counter.fail(result.cause()); } else { if (!watchHandlers.containsKey(instance.address())) { final Handler<MapEvent<String, String>> watchHandler = new Handler<MapEvent<String, String>>() { @Override public void handle(MapEvent<String, String> event) { if (event.type().equals(MapEvent.Type.CREATE) || event.type().equals(MapEvent.Type.UPDATE)) { handleReady(instance.address()); } else if (event.type().equals(MapEvent.Type.DELETE)) { handleUnready(instance.address()); } } }; // Watch the instance's status for changes. Once the instance has started // up, the component coordinator will set the instance's status key in the // cluster, indicating that the instance has completed started. Once all // instances in the network have completed startup the network will be started. data.watch(instance.status(), watchHandler, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { counter.fail(result.cause()); } else { watchHandlers.put(instance.address(), watchHandler); if (instance.component().isModule()) { deployModule(node, instance, counter); } else if (instance.component().isVerticle() && !instance.component().asVerticle().isWorker()) { deployVerticle(node, instance, counter); } else if (instance.component().isVerticle() && instance.component().asVerticle().isWorker()) { deployWorkerVerticle(node, instance, counter); } } } }); } else { if (instance.component().isModule()) { deployModule(node, instance, counter); } else if (instance.component().isVerticle() && !instance.component().asVerticle().isWorker()) { deployVerticle(node, instance, counter); } else if (instance.component().isVerticle() && instance.component().asVerticle().isWorker()) { deployWorkerVerticle(node, instance, counter); } } } } }); }
[ "private", "void", "deployInstance", "(", "final", "Node", "node", ",", "final", "InstanceContext", "instance", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "data", ".", "put", "(", "instance", ".", "address", "(", ")", "...
Deploys an instance to a specific node.
[ "Deploys", "an", "instance", "to", "a", "specific", "node", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L777-L828
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.deployModule
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(), Components.buildConfig(instance, cluster), 1, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { deploymentIDs.put(instance.address(), result.result(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { counter.succeed(); } }); } } }); }
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(), Components.buildConfig(instance, cluster), 1, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { deploymentIDs.put(instance.address(), result.result(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { counter.succeed(); } }); } } }); }
[ "private", "void", "deployModule", "(", "final", "Node", "node", ",", "final", "InstanceContext", "instance", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Depl...
Deploys a module component instance in the network's cluster.
[ "Deploys", "a", "module", "component", "instance", "in", "the", "network", "s", "cluster", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L833-L850
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.installModules
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()); } } final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(modules.size()).setHandler(doneHandler); for (ModuleContext module : modules) { installModule(node, module, counter); } }
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()); } } final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(modules.size()).setHandler(doneHandler); for (ModuleContext module : modules) { installModule(node, module, counter); } }
[ "private", "void", "installModules", "(", "final", "Node", "node", ",", "final", "NetworkContext", "context", ",", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "List", "<", "ModuleContext", ">", "modules", "=", "new...
Installs all modules on a node.
[ "Installs", "all", "modules", "on", "a", "node", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L899-L911
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.installModule
private void installModule(final Node node, final ModuleContext module, final Handler<AsyncResult<Void>> doneHandler) { node.installModule(module.module(), doneHandler); }
java
private void installModule(final Node node, final ModuleContext module, final Handler<AsyncResult<Void>> doneHandler) { node.installModule(module.module(), doneHandler); }
[ "private", "void", "installModule", "(", "final", "Node", "node", ",", "final", "ModuleContext", "module", ",", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "node", ".", "installModule", "(", "module", ".", "module"...
Installs a module on a node.
[ "Installs", "a", "module", "on", "a", "node", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L916-L918
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.undeployComponents
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()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { complete.fail(result.cause()); } else { // Remove the component's context from the cluster. data.remove(component.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { complete.fail(result.cause()); } else { complete.succeed(); } } }); } } }); undeployInstances(component.instances(), counter); } }
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()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { complete.fail(result.cause()); } else { // Remove the component's context from the cluster. data.remove(component.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { complete.fail(result.cause()); } else { complete.succeed(); } } }); } } }); undeployInstances(component.instances(), counter); } }
[ "private", "void", "undeployComponents", "(", "Collection", "<", "ComponentContext", "<", "?", ">", ">", "components", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "complete", ")", "{", "for", "(", "final", "ComponentContext", "<", "?", ">", "c...
Undeploys all network components.
[ "Undeploys", "all", "network", "components", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L941-L966
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.undeployInstances
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()) { undeployVerticle(instance, counter); } } }
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()) { undeployVerticle(instance, counter); } } }
[ "private", "void", "undeployInstances", "(", "List", "<", "InstanceContext", ">", "instances", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "for", "(", "final", "InstanceContext", "instance", ":", "instances", ")", "{", "if",...
Undeploys all component instances.
[ "Undeploys", "all", "component", "instances", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L971-L979
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.unwatchInstance
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>>() { @Override public void handle(AsyncResult<Void> result) { data.remove(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }); } else { data.remove(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }
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>>() { @Override public void handle(AsyncResult<Void> result) { data.remove(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }); } else { data.remove(instance.address(), new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }
[ "private", "void", "unwatchInstance", "(", "final", "InstanceContext", "instance", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "Handler", "<", "MapEvent", "<", "String", ",", "String", ">", ">", "watchHandler", "=", "watchHa...
Unwatches a component instance's status and context.
[ "Unwatches", "a", "component", "instance", "s", "status", "and", "context", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L984-L1014
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.undeployModule
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(result.cause()); } else if (result.result() != null) { cluster.undeployModule(result.result(), new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { unwatchInstance(instance, counter); } }); } else { unwatchInstance(instance, counter); } } }); }
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(result.cause()); } else if (result.result() != null) { cluster.undeployModule(result.result(), new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { unwatchInstance(instance, counter); } }); } else { unwatchInstance(instance, counter); } } }); }
[ "private", "void", "undeployModule", "(", "final", "InstanceContext", "instance", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "deploymentIDs", ".", "remove", "(", "instance", ".", "address", "(", ")", ",", "new", "Handler", ...
Undeploys a module component instance.
[ "Undeploys", "a", "module", "component", "instance", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1019-L1037
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.updateNetwork
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 handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); updateComponents(context.components(), complete); }
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 handle(AsyncResult<Void> result) { if (result.failed()) { new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler); } else { new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } } }); updateComponents(context.components(), complete); }
[ "private", "void", "updateNetwork", "(", "final", "NetworkContext", "context", ",", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "final", "CountingCompletionHandler", "<", "Void", ">", "complete", "=", "new", "CountingC...
Updates a network.
[ "Updates", "a", "network", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1065-L1078
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.updateComponents
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.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { complete.fail(result.cause()); } else { complete.succeed(); } } }); updateInstances(component.instances(), counter); } }
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.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { complete.fail(result.cause()); } else { complete.succeed(); } } }); updateInstances(component.instances(), counter); } }
[ "private", "void", "updateComponents", "(", "Collection", "<", "ComponentContext", "<", "?", ">", ">", "components", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "complete", ")", "{", "for", "(", "final", "ComponentContext", "<", "?", ">", "com...
Updates all network components.
[ "Updates", "all", "network", "components", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1083-L1098
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.updateInstances
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 handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }
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 handle(AsyncResult<String> result) { if (result.failed()) { counter.fail(result.cause()); } else { counter.succeed(); } } }); } }
[ "private", "void", "updateInstances", "(", "List", "<", "InstanceContext", ">", "instances", ",", "final", "CountingCompletionHandler", "<", "Void", ">", "counter", ")", "{", "for", "(", "final", "InstanceContext", "instance", ":", "instances", ")", "{", "data",...
Updates all component instances.
[ "Updates", "all", "component", "instances", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1103-L1116
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.doNodeJoined
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())); installModules(node, currentContext, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully uploaded components to %s", NetworkManager.this, node.address())); } task.complete(); } }); } else { task.complete(); } } }); }
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())); installModules(node, currentContext, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { if (result.failed()) { log.error(result.cause()); } else { log.info(String.format("%s - Successfully uploaded components to %s", NetworkManager.this, node.address())); } task.complete(); } }); } else { task.complete(); } } }); }
[ "private", "void", "doNodeJoined", "(", "final", "Node", "node", ")", "{", "tasks", ".", "runTask", "(", "new", "Handler", "<", "Task", ">", "(", ")", "{", "@", "Override", "public", "void", "handle", "(", "final", "Task", "task", ")", "{", "if", "("...
Handles a node joining the cluster.
[ "Handles", "a", "node", "joining", "the", "cluster", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1121-L1143
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java
NetworkManager.doNodeLeft
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())); deploymentNodes.keySet(new Handler<AsyncResult<Set<String>>>() { @Override public void handle(AsyncResult<Set<String>> result) { if (result.succeeded()) { final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(result.result().size()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { task.complete(); } }); // If the instance was deployed on the node that left the cluster then // redeploy it on a new node. for (final String instanceAddress : result.result()) { deploymentNodes.get(instanceAddress, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.succeeded() && result.result().equals(node.address())) { // Look up the current instance context in the cluster. data.get(instanceAddress, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.succeeded() && result.result() != null) { deployInstance(Contexts.<InstanceContext>deserialize(new JsonObject(result.result())), counter); } else { counter.succeed(); } } }); } else { counter.succeed(); } } }); } } } }); } else { task.complete(); } } }); }
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())); deploymentNodes.keySet(new Handler<AsyncResult<Set<String>>>() { @Override public void handle(AsyncResult<Set<String>> result) { if (result.succeeded()) { final CountingCompletionHandler<Void> counter = new CountingCompletionHandler<Void>(result.result().size()); counter.setHandler(new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> result) { task.complete(); } }); // If the instance was deployed on the node that left the cluster then // redeploy it on a new node. for (final String instanceAddress : result.result()) { deploymentNodes.get(instanceAddress, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.succeeded() && result.result().equals(node.address())) { // Look up the current instance context in the cluster. data.get(instanceAddress, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> result) { if (result.succeeded() && result.result() != null) { deployInstance(Contexts.<InstanceContext>deserialize(new JsonObject(result.result())), counter); } else { counter.succeed(); } } }); } else { counter.succeed(); } } }); } } } }); } else { task.complete(); } } }); }
[ "private", "void", "doNodeLeft", "(", "final", "Node", "node", ")", "{", "tasks", ".", "runTask", "(", "new", "Handler", "<", "Task", ">", "(", ")", "{", "@", "Override", "public", "void", "handle", "(", "final", "Task", "task", ")", "{", "if", "(", ...
Handles a node leaving the cluster.
[ "Handles", "a", "node", "leaving", "the", "cluster", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/network/manager/NetworkManager.java#L1148-L1198
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.disconnect
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.failed()) { ReplyException failure = (ReplyException) result.cause(); if (failure.failureType().equals(ReplyFailure.RECIPIENT_FAILURE)) { log.warn(String.format("%s - Failed to disconnect from %s", DefaultOutputConnection.this, context.target()), result.cause()); new DefaultFutureResult<Void>(failure).setHandler(doneHandler); } else if (failure.failureType().equals(ReplyFailure.NO_HANDLERS)) { log.info(String.format("%s - Disconnected from %s", DefaultOutputConnection.this, context.target())); new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } else { log.debug(String.format("%s - Disconnection from %s failed, retrying", DefaultOutputConnection.this, context.target())); disconnect(doneHandler); } } else if (result.result().body()) { log.info(String.format("%s - Disconnected from %s", DefaultOutputConnection.this, context.target())); open = false; new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } else { log.debug(String.format("%s - Disconnection from %s failed, retrying", DefaultOutputConnection.this, context.target())); vertx.setTimer(500, new Handler<Long>() { @Override public void handle(Long timerID) { disconnect(doneHandler); } }); } } }); }
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.failed()) { ReplyException failure = (ReplyException) result.cause(); if (failure.failureType().equals(ReplyFailure.RECIPIENT_FAILURE)) { log.warn(String.format("%s - Failed to disconnect from %s", DefaultOutputConnection.this, context.target()), result.cause()); new DefaultFutureResult<Void>(failure).setHandler(doneHandler); } else if (failure.failureType().equals(ReplyFailure.NO_HANDLERS)) { log.info(String.format("%s - Disconnected from %s", DefaultOutputConnection.this, context.target())); new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } else { log.debug(String.format("%s - Disconnection from %s failed, retrying", DefaultOutputConnection.this, context.target())); disconnect(doneHandler); } } else if (result.result().body()) { log.info(String.format("%s - Disconnected from %s", DefaultOutputConnection.this, context.target())); open = false; new DefaultFutureResult<Void>((Void) null).setHandler(doneHandler); } else { log.debug(String.format("%s - Disconnection from %s failed, retrying", DefaultOutputConnection.this, context.target())); vertx.setTimer(500, new Handler<Long>() { @Override public void handle(Long timerID) { disconnect(doneHandler); } }); } } }); }
[ "private", "void", "disconnect", "(", "final", "Handler", "<", "AsyncResult", "<", "Void", ">", ">", "doneHandler", ")", "{", "eventBus", ".", "sendWithTimeout", "(", "inAddress", ",", "new", "JsonObject", "(", ")", ".", "putString", "(", "\"action\"", ",", ...
Disconnects from the other side of the connection.
[ "Disconnects", "from", "the", "other", "side", "of", "the", "connection", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L288-L319
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.checkFull
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 checkFull() { if (!full && messages.size() >= maxQueueSize) { full = true; log.debug(String.format("%s - Connection to %s is full", this, context.target())); } }
[ "private", "void", "checkFull", "(", ")", "{", "if", "(", "!", "full", "&&", "messages", ".", "size", "(", ")", ">=", "maxQueueSize", ")", "{", "full", "=", "true", ";", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Connection to %s i...
Checks whether the connection is full.
[ "Checks", "whether", "the", "connection", "is", "full", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L331-L336
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.checkDrain
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 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); } } }
[ "private", "void", "checkDrain", "(", ")", "{", "if", "(", "full", "&&", "!", "paused", "&&", "messages", ".", "size", "(", ")", "<", "maxQueueSize", "/", "2", ")", "{", "full", "=", "false", ";", "log", ".", "debug", "(", "String", ".", "format", ...
Checks whether the connection has been drained.
[ "Checks", "whether", "the", "connection", "has", "been", "drained", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L341-L349
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doAck
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 from memory", this, id)); } if (messages.containsKey(id+1)) { messages.tailMap(id+1); } else { messages.clear(); } checkDrain(); }
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 from memory", this, id)); } if (messages.containsKey(id+1)) { messages.tailMap(id+1); } else { messages.clear(); } checkDrain(); }
[ "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",...
Handles a batch ack.
[ "Handles", "a", "batch", "ack", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L373-L385
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doFail
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 iterate over the messages map and resend all the messages. Iterator<Map.Entry<Long, JsonObject>> iter = messages.entrySet().iterator(); while (iter.hasNext()) { eventBus.send(inAddress, iter.next().getValue()); } }
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 iterate over the messages map and resend all the messages. Iterator<Map.Entry<Long, JsonObject>> iter = messages.entrySet().iterator(); while (iter.hasNext()) { eventBus.send(inAddress, iter.next().getValue()); } }
[ "private", "void", "doFail", "(", "long", "id", ")", "{", "if", "(", "log", ".", "isDebugEnabled", "(", ")", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Received resend request for messages starting at %d\"", ",", "this", ",", "...
Handles a batch fail.
[ "Handles", "a", "batch", "fail", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L390-L404
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doPause
private void doPause(long id) { log.debug(String.format("%s - Paused connection to %s", this, context.target())); paused = true; }
java
private void doPause(long id) { log.debug(String.format("%s - Paused connection to %s", this, context.target())); paused = true; }
[ "private", "void", "doPause", "(", "long", "id", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Paused connection to %s\"", ",", "this", ",", "context", ".", "target", "(", ")", ")", ")", ";", "paused", "=", "true", ";", "}" ...
Handles a connection pause.
[ "Handles", "a", "connection", "pause", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L409-L412
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doResume
private void doResume(long id) { if (paused) { log.debug(String.format("%s - Resumed connection to %s", this, context.target())); paused = false; checkDrain(); } }
java
private void doResume(long id) { if (paused) { log.debug(String.format("%s - Resumed connection to %s", this, context.target())); paused = false; checkDrain(); } }
[ "private", "void", "doResume", "(", "long", "id", ")", "{", "if", "(", "paused", ")", "{", "log", ".", "debug", "(", "String", ".", "format", "(", "\"%s - Resumed connection to %s\"", ",", "this", ",", "context", ".", "target", "(", ")", ")", ")", ";",...
Handles a connection resume.
[ "Handles", "a", "connection", "resume", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L417-L423
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doGroupStart
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) { if (log.isDebugEnabled()) { if (parent != null) { log.debug(String.format("%s - Group start: Group[name=%s, group=%s, parent=%s, args=%s]", this, name, group, parent, args)); } else { log.debug(String.format("%s - Group start: Group[name=%s, group=%s, args=%s]", this, name, group, args)); } } eventBus.send(inAddress, message); } checkFull(); }
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) { if (log.isDebugEnabled()) { if (parent != null) { log.debug(String.format("%s - Group start: Group[name=%s, group=%s, parent=%s, args=%s]", this, name, group, parent, args)); } else { log.debug(String.format("%s - Group start: Group[name=%s, group=%s, args=%s]", this, name, group, args)); } } eventBus.send(inAddress, message); } checkFull(); }
[ "void", "doGroupStart", "(", "String", "group", ",", "String", "name", ",", "Object", "args", ",", "String", "parent", ")", "{", "checkOpen", "(", ")", ";", "JsonObject", "message", "=", "createMessage", "(", "args", ")", ".", "putString", "(", "\"group\""...
Sends a group start message.
[ "Sends", "a", "group", "start", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L448-L466
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doGroupSend
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, message=%s", this, group, message.getLong("id"), value)); } eventBus.send(inAddress, message); } for (OutputHook hook : hooks) { hook.handleSend(value); } checkFull(); }
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, message=%s", this, group, message.getLong("id"), value)); } eventBus.send(inAddress, message); } for (OutputHook hook : hooks) { hook.handleSend(value); } checkFull(); }
[ "void", "doGroupSend", "(", "String", "group", ",", "Object", "value", ")", "{", "checkOpen", "(", ")", ";", "JsonObject", "message", "=", "createMessage", "(", "value", ")", ".", "putString", "(", "\"action\"", ",", "\"group\"", ")", ".", "putString", "("...
Sends a group message.
[ "Sends", "a", "group", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L471-L486
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doGroupEnd
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]", this, group, args)); } eventBus.send(inAddress, message); } groups.remove(group); }
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]", this, group, args)); } eventBus.send(inAddress, message); } groups.remove(group); }
[ "void", "doGroupEnd", "(", "String", "group", ",", "Object", "args", ")", "{", "checkOpen", "(", ")", ";", "JsonObject", "message", "=", "createMessage", "(", "args", ")", ".", "putString", "(", "\"action\"", ",", "\"endGroup\"", ")", ".", "putString", "("...
Sends a group end message.
[ "Sends", "a", "group", "end", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L491-L503
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doBatchStart
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]", this, batch)); } eventBus.send(inAddress, message); } checkFull(); }
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]", this, batch)); } eventBus.send(inAddress, message); } checkFull(); }
[ "void", "doBatchStart", "(", "String", "batch", ",", "Object", "args", ")", "{", "checkOpen", "(", ")", ";", "JsonObject", "message", "=", "createMessage", "(", "args", ")", ".", "putString", "(", "\"batch\"", ",", "batch", ")", ".", "putString", "(", "\...
Sends a batch start message.
[ "Sends", "a", "batch", "start", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L508-L520
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.doBatchEnd
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]", this, batch, args)); } eventBus.send(inAddress, message); } if (currentBatch != null && currentBatch.id().equals(batch)) { currentBatch = null; } }
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]", this, batch, args)); } eventBus.send(inAddress, message); } if (currentBatch != null && currentBatch.id().equals(batch)) { currentBatch = null; } }
[ "void", "doBatchEnd", "(", "String", "batch", ",", "Object", "args", ")", "{", "checkOpen", "(", ")", ";", "JsonObject", "message", "=", "createMessage", "(", "args", ")", ".", "putString", "(", "\"action\"", ",", "\"endBatch\"", ")", ".", "putString", "("...
Sends a batch end message.
[ "Sends", "a", "batch", "end", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L545-L559
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java
DefaultOutputConnection.createMessage
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); messages.put(id, message); return message; }
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); messages.put(id, message); return message; }
[ "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...
Creates a value message.
[ "Creates", "a", "value", "message", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultOutputConnection.java#L564-L573
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Args.java
Args.checkNull
public static void checkNull(Object value, String message, Object... args) { if (value != null) { throw new IllegalArgumentException(String.format(message, args)); } }
java
public static void checkNull(Object value, String message, Object... args) { if (value != null) { throw new IllegalArgumentException(String.format(message, args)); } }
[ "public", "static", "void", "checkNull", "(", "Object", "value", ",", "String", "message", ",", "Object", "...", "args", ")", "{", "if", "(", "value", "!=", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "String", ".", "format", "(", ...
Validates that an argument is null. @param value The value to check. @param message An exception message. @param args Exception message arguments.
[ "Validates", "that", "an", "argument", "is", "null", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Args.java#L46-L50
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Args.java
Args.checkNotNull
public static void checkNotNull(Object value, String message, Object... args) { if (value == null) { throw new NullPointerException(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)); } }
[ "public", "static", "void", "checkNotNull", "(", "Object", "value", ",", "String", "message", ",", "Object", "...", "args", ")", "{", "if", "(", "value", "==", "null", ")", "{", "throw", "new", "NullPointerException", "(", "String", ".", "format", "(", "...
Validates that an argument is not null. @param value The value to check. @param message An exception message. @param args Exception message arguments.
[ "Validates", "that", "an", "argument", "is", "not", "null", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Args.java#L70-L74
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Args.java
Args.checkPositive
public static void checkPositive(int number, String message, Object... args) { if (number < 0) { throw new IllegalArgumentException(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)); } }
[ "public", "static", "void", "checkPositive", "(", "int", "number", ",", "String", "message", ",", "Object", "...", "args", ")", "{", "if", "(", "number", "<", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "String", ".", "format", "(", "...
Validates that an argument is positive. @param value The value to check. @param message An exception message. @param args Exception message arguments.
[ "Validates", "that", "an", "argument", "is", "positive", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Args.java#L94-L98
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/util/Args.java
Args.checkUri
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
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); } }
[ "public", "static", "void", "checkUri", "(", "String", "uri", ",", "String", "message", ",", "Object", "...", "args", ")", "{", "try", "{", "new", "URI", "(", "uri", ")", ";", "}", "catch", "(", "URISyntaxException", "e", ")", "{", "throw", "new", "I...
Validates that an argument is a valid URI. @param uri The value to check. @param message An exception message. @param args Exception message arguments.
[ "Validates", "that", "an", "argument", "is", "a", "valid", "URI", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/util/Args.java#L120-L126
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputGroup.java
DefaultConnectionOutputGroup.start
void start(final Handler<OutputGroup> startHandler) { connection.doGroupStart(id, name, args, parent); this.startHandler = startHandler; }
java
void start(final Handler<OutputGroup> startHandler) { connection.doGroupStart(id, name, args, parent); this.startHandler = startHandler; }
[ "void", "start", "(", "final", "Handler", "<", "OutputGroup", ">", "startHandler", ")", "{", "connection", ".", "doGroupStart", "(", "id", ",", "name", ",", "args", ",", "parent", ")", ";", "this", ".", "startHandler", "=", "startHandler", ";", "}" ]
Starts the output group.
[ "Starts", "the", "output", "group", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/connection/impl/DefaultConnectionOutputGroup.java#L103-L106
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/logging/PortLoggerFactory.java
PortLoggerFactory.getLogger
public static PortLogger getLogger(Class<?> clazz, OutputCollector output) { return getLogger(clazz.getCanonicalName(), output); }
java
public static PortLogger getLogger(Class<?> clazz, OutputCollector output) { return getLogger(clazz.getCanonicalName(), output); }
[ "public", "static", "PortLogger", "getLogger", "(", "Class", "<", "?", ">", "clazz", ",", "OutputCollector", "output", ")", "{", "return", "getLogger", "(", "clazz", ".", "getCanonicalName", "(", ")", ",", "output", ")", ";", "}" ]
Creates an output port logger for the given type. @param clazz The type being logged. @param output The output to which to log messages. @return An output port logger.
[ "Creates", "an", "output", "port", "logger", "for", "the", "given", "type", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/logging/PortLoggerFactory.java#L41-L43
train
kuujo/vertigo
core/src/main/java/net/kuujo/vertigo/io/logging/PortLoggerFactory.java
PortLoggerFactory.getLogger
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, loggers); } PortLogger logger = loggers.get(output); if (logger == null) { logger = new PortLogger(LoggerFactory.getLogger(name), output); loggers.put(output, logger); } return logger; }
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, loggers); } PortLogger logger = loggers.get(output); if (logger == null) { logger = new PortLogger(LoggerFactory.getLogger(name), output); loggers.put(output, logger); } return logger; }
[ "public", "static", "PortLogger", "getLogger", "(", "String", "name", ",", "OutputCollector", "output", ")", "{", "Args", ".", "checkNotNull", "(", "name", ",", "\"logger name cannot be null\"", ")", ";", "Map", "<", "OutputCollector", ",", "PortLogger", ">", "l...
Creates an output port logger with the given name. @param name The logger name. @param output The output to which to log messages. @return An output port logger.
[ "Creates", "an", "output", "port", "logger", "with", "the", "given", "name", "." ]
c5869dbc5fff89eb5262e83f7a81719b01a5ba6f
https://github.com/kuujo/vertigo/blob/c5869dbc5fff89eb5262e83f7a81719b01a5ba6f/core/src/main/java/net/kuujo/vertigo/io/logging/PortLoggerFactory.java#L52-L66
train