idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
12,900 | 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 ( ) ; } | Sends a batch start message . |
12,901 | 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 ; } } | Sends a batch end message . |
12,902 | private JsonObject createMessage ( Object value ) { JsonObject message = serializer . serialize ( value ) ; long id = currentMessage ++ ; message . putNumber ( "id" , id ) ; messages . put ( id , message ) ; return message ; } | Creates a value message . |
12,903 | public static void checkNull ( Object value , String message , Object ... args ) { if ( value != null ) { throw new IllegalArgumentException ( String . format ( message , args ) ) ; } } | Validates that an argument is null . |
12,904 | public static void checkNotNull ( Object value , String message , Object ... args ) { if ( value == null ) { throw new NullPointerException ( String . format ( message , args ) ) ; } } | Validates that an argument is not null . |
12,905 | public static void checkPositive ( int number , String message , Object ... args ) { if ( number < 0 ) { throw new IllegalArgumentException ( String . format ( message , args ) ) ; } } | Validates that an argument is positive . |
12,906 | 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 ) ; } } | Validates that an argument is a valid URI . |
12,907 | void start ( final Handler < OutputGroup > startHandler ) { connection . doGroupStart ( id , name , args , parent ) ; this . startHandler = startHandler ; } | Starts the output group . |
12,908 | public static PortLogger getLogger ( Class < ? > clazz , OutputCollector output ) { return getLogger ( clazz . getCanonicalName ( ) , output ) ; } | Creates an output port logger for the given type . |
12,909 | 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 ; } | Creates an output port logger with the given name . |
12,910 | private boolean checkID ( long id ) { if ( lastReceived == 0 || id == lastReceived + 1 || id < lastReceived ) { lastReceived = id ; if ( lastReceived % BATCH_SIZE == 0 ) { ack ( ) ; } return true ; } else { fail ( ) ; } return false ; } | Checks that the given ID is valid . |
12,911 | private void ack ( ) { if ( open && connected ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Acking messages up to: %d" , this , lastReceived ) ) ; } eventBus . send ( outAddress , new JsonObject ( ) . putString ( "action" , "ack" ) . putNumber ( "id" , lastReceived ) ) ; lastFeedbackTime = System . currentTimeMillis ( ) ; } } | Sends an ack message for the current received count . |
12,912 | @ SuppressWarnings ( "unchecked" ) private void doMessage ( final JsonObject message ) { Object value = deserializer . deserialize ( message ) ; if ( value != null && messageHandler != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Received: Message[id=%d, value=%s]" , this , message . getLong ( "id" ) , value ) ) ; } messageHandler . handle ( value ) ; } for ( InputHook hook : hooks ) { hook . handleReceive ( value ) ; } } | Handles receiving a message . |
12,913 | void groupReady ( String group ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Group ready: Group[group=%s]" , this , group ) ) ; } eventBus . send ( outAddress , new JsonObject ( ) . putString ( "action" , "group" ) . putString ( "group" , group ) ) ; } | Indicates that an input group is ready . |
12,914 | private void doGroupMessage ( final JsonObject message ) { String groupID = message . getString ( "group" ) ; DefaultConnectionInputGroup group = groups . get ( groupID ) ; if ( group != null ) { Object value = deserializer . deserialize ( message ) ; if ( value != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Group received: Group[group=%s, id=%d, message=%s" , this , groupID , message . getLong ( "id" ) , value ) ) ; } group . handleMessage ( value ) ; } } } | Handles a group message . |
12,915 | private void doGroupEnd ( final JsonObject message ) { String groupID = message . getString ( "group" ) ; DefaultConnectionInputGroup group = groups . remove ( groupID ) ; if ( group != null ) { Object args = deserializer . deserialize ( message ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Group ended: Group[group=%s, args=%s]" , this , group . id ( ) , args ) ) ; } group . handleEnd ( args ) ; } } | Handles a group end . |
12,916 | void batchReady ( String batch ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Batch ready: Batch[batch=%s]" , this , batch ) ) ; } eventBus . send ( outAddress , new JsonObject ( ) . putString ( "action" , "batch" ) . putString ( "batch" , batch ) ) ; } | Indicates that an input batch is ready . |
12,917 | private void doBatchMessage ( final JsonObject message ) { String batchID = message . getString ( "batch" ) ; if ( currentBatch != null && currentBatch . id ( ) . equals ( batchID ) ) { Object value = deserializer . deserialize ( message ) ; if ( value != null ) { if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Batch received: Batch[batch=%s, id=%d, message=%s]" , this , batchID , message . getLong ( "id" ) , value ) ) ; } currentBatch . handleMessage ( value ) ; } } } | Handles a batch message . |
12,918 | private void doBatchEnd ( final JsonObject message ) { if ( currentBatch != null ) { Object args = deserializer . deserialize ( message ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "%s - Batch ended: Batch[batch=%s, args=%s]" , this , currentBatch . id ( ) , args ) ) ; } currentBatch . handleEnd ( args ) ; currentBatch = null ; } } | Handles a batch end . |
12,919 | private void doConnect ( final Message < JsonObject > message ) { if ( open ) { if ( ! connected ) { groups . clear ( ) ; connected = true ; } message . reply ( true ) ; log . debug ( String . format ( "%s - Accepted connect request from %s" , this , context . source ( ) ) ) ; } else { message . reply ( false ) ; log . debug ( String . format ( "%s - Rejected connect request from %s, connection not open" , this , context . source ( ) ) ) ; } } | Handles connect . |
12,920 | synchronized static PersistentPropertyStorage newPersistentPropertyStorage ( String propertyFile ) throws IOException { File file = new File ( propertyFile ) ; String canonicalName = file . getCanonicalPath ( ) ; if ( propertyFileMap . containsKey ( canonicalName ) ) { return ( PersistentPropertyStorage ) propertyFileMap . get ( canonicalName ) ; } PersistentPropertyStorage storage = new PersistentPropertyStorage ( file ) ; propertyFileMap . put ( canonicalName , storage ) ; return storage ; } | Factory method for PersistentPropertyStorage . Guarantees that only a single PersistentPropertyStorage object exists for any property file . |
12,921 | public void locateCluster ( String cluster , Handler < AsyncResult < String > > doneHandler ) { Set < String > registry = vertx . sharedData ( ) . getSet ( cluster ) ; synchronized ( registry ) { if ( ! registry . isEmpty ( ) ) { locateNode ( cluster , new HashSet < > ( registry ) , doneHandler ) ; } } } | Locates the local address of the nearest node if one exists . |
12,922 | private void locateNode ( String address , Set < String > nodes , Handler < AsyncResult < String > > doneHandler ) { locateNode ( address , nodes . iterator ( ) , doneHandler ) ; } | Locates an active local node in a set of nodes . |
12,923 | private void locateNode ( final String address , final Iterator < String > nodes , final Handler < AsyncResult < String > > doneHandler ) { if ( nodes . hasNext ( ) ) { final String node = nodes . next ( ) ; vertx . eventBus ( ) . sendWithTimeout ( node , new JsonObject ( ) . putString ( "action" , "ping" ) , 1000 , new Handler < AsyncResult < Message < JsonObject > > > ( ) { public void handle ( AsyncResult < Message < JsonObject > > result ) { if ( result . failed ( ) || result . result ( ) . body ( ) . getString ( "status" , "ok" ) . equals ( "error" ) ) { removeNode ( address , node ) ; locateNode ( address , nodes , doneHandler ) ; } else { new DefaultFutureResult < String > ( node ) . setHandler ( doneHandler ) ; } } } ) ; } else { new DefaultFutureResult < String > ( new IllegalStateException ( "No local nodes found" ) ) . setHandler ( doneHandler ) ; } } | Locates an active local node in a list of nodes . |
12,924 | private void removeNode ( String address , String node ) { Set < String > registry = vertx . sharedData ( ) . getSet ( address ) ; registry . remove ( node ) ; } | Removes a node from the local registry . |
12,925 | @ SuppressWarnings ( "unchecked" ) public static < T extends ComponentConfig < T > > T createComponent ( JsonObject config ) { return ( T ) serializer . deserializeObject ( config , ComponentConfig . class ) ; } | Creates a component configuration from json . |
12,926 | public static NetworkConfig mergeNetworks ( NetworkConfig base , NetworkConfig merge ) { if ( ! base . getName ( ) . equals ( merge . getName ( ) ) ) { throw new IllegalArgumentException ( "Cannot merge networks of different names." ) ; } for ( ComponentConfig < ? > component : merge . getComponents ( ) ) { if ( ! base . hasComponent ( component . getName ( ) ) ) { base . addComponent ( component ) ; } } for ( ConnectionConfig connection : merge . getConnections ( ) ) { boolean exists = false ; for ( ConnectionConfig existing : base . getConnections ( ) ) { if ( existing . equals ( connection ) ) { exists = true ; break ; } } if ( ! exists ) { base . createConnection ( connection ) ; } } return base ; } | Merges two network configurations into a single configuraiton . |
12,927 | public static NetworkConfig unmergeNetworks ( NetworkConfig base , NetworkConfig unmerge ) { if ( ! base . getName ( ) . equals ( unmerge . getName ( ) ) ) { throw new IllegalArgumentException ( "Cannot merge networks of different names." ) ; } for ( ComponentConfig < ? > component : unmerge . getComponents ( ) ) { base . removeComponent ( component . getName ( ) ) ; } for ( ConnectionConfig connection : unmerge . getConnections ( ) ) { base . destroyConnection ( connection ) ; } return base ; } | Unmerges one network configuration from another . |
12,928 | public < T > ContextManager execute ( Action < T > action , Handler < AsyncResult < T > > resultHandler ) { vertx . executeBlocking ( action , resultHandler ) ; return this ; } | Executes a blocking action on a background thread . |
12,929 | public final void onDismissed ( Snackbar snackbar , int dismissEvent ) { super . onDismissed ( snackbar , dismissEvent ) ; notifySnackbarCallback ( snackbar , dismissEvent ) ; } | Notifies that the Snackbar has been dismissed through some event for example swiping or the action being pressed . |
12,930 | private void closeFile ( final String filePath , AsyncFile file ) { file . close ( new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { try { input . vertx ( ) . fileSystem ( ) . deleteSync ( filePath ) ; } catch ( Exception e ) { } if ( exceptionHandler != null ) { exceptionHandler . handle ( result . cause ( ) ) ; } } else if ( fileHandler != null ) { fileHandler . handle ( filePath ) ; } } } ) ; } | Closes a file . |
12,931 | private String getClusterMain ( ) { if ( clusterMain == null ) { try { clusterMain = System . getProperty ( CLUSTER_MAIN_PROPERTY_NAME ) ; } catch ( Exception e ) { } clusterMain = ClusterAgent . class . getName ( ) ; } return clusterMain ; } | Loads the current cluster verticle . |
12,932 | public Vertigo deployCluster ( Handler < AsyncResult < Cluster > > doneHandler ) { return deployCluster ( ContextUri . createUniqueScheme ( ) , doneHandler ) ; } | Deploys a randomly named unique cluster . |
12,933 | public Vertigo getCluster ( String address , Handler < AsyncResult < Cluster > > resultHandler ) { Cluster cluster = new DefaultCluster ( address , vertx , container ) ; cluster . ping ( resultHandler ) ; return this ; } | Loads a cluster . |
12,934 | protected void checkAddress ( ) { if ( localAddress == null ) { check ++ ; if ( check > 1000 && System . currentTimeMillis ( ) - lastReset > 15000 ) { resetLocalAddress ( null ) ; } } } | Checks whether the local cluster address needs to be updated . |
12,935 | protected void resetLocalAddress ( final Handler < AsyncResult < Boolean > > doneHandler ) { localAddress = null ; lastReset = System . currentTimeMillis ( ) ; clusterLocator . locateCluster ( address , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . succeeded ( ) && result . result ( ) != null ) { localAddress = result . result ( ) ; new DefaultFutureResult < Boolean > ( true ) . setHandler ( doneHandler ) ; } else { new DefaultFutureResult < Boolean > ( false ) . setHandler ( doneHandler ) ; } } } ) ; } | Updates the known local group address . |
12,936 | public static JsonObject serialize ( Context < ? > context ) { if ( context instanceof NetworkContext ) { return serialize ( NetworkContext . class . cast ( context ) ) ; } else if ( context instanceof ComponentContext ) { return serialize ( ComponentContext . class . cast ( context ) ) ; } else if ( context instanceof InstanceContext ) { return serialize ( InstanceContext . class . cast ( context ) ) ; } else if ( context instanceof IOContext ) { return serialize ( IOContext . class . cast ( context ) ) ; } else if ( context instanceof InputPortContext ) { return serialize ( InputPortContext . class . cast ( context ) ) ; } else if ( context instanceof OutputPortContext ) { return serialize ( OutputPortContext . class . cast ( context ) ) ; } else { throw new UnsupportedOperationException ( "Cannot serialize " + context . getClass ( ) . getCanonicalName ( ) + " type contexts" ) ; } } | Serializes a context to JSON . |
12,937 | public static JsonObject serialize ( InstanceContext context ) { return serialize ( context . uri ( ) , context . component ( ) . network ( ) ) ; } | Serializes an instance context to JSON . |
12,938 | public static JsonObject serialize ( InputPortContext context ) { return serialize ( context . uri ( ) , context . input ( ) . instance ( ) . component ( ) . network ( ) ) ; } | Serializes an input port context to JSON . |
12,939 | public static JsonObject serialize ( OutputPortContext context ) { return serialize ( context . uri ( ) , context . output ( ) . instance ( ) . component ( ) . network ( ) ) ; } | Serializes an output port context to JSON . |
12,940 | public static < T extends Context < T > > T deserialize ( JsonObject context ) { return deserialize ( context . getString ( "uri" ) , context . getObject ( "context" ) ) ; } | Deserializes a context from JSON . |
12,941 | public boolean get ( boolean defaultValue ) { final String value = getInternal ( Boolean . toString ( defaultValue ) , false ) ; if ( value == null ) { return defaultValue ; } return toBoolean ( value ) ; } | Retrieves the value of this boolean property . |
12,942 | public boolean set ( boolean value ) { String prevValue = setString ( Boolean . toString ( value ) ) ; if ( prevValue == null ) { prevValue = getDefaultValue ( ) ; if ( prevValue == null ) { return false ; } } return toBoolean ( prevValue ) ; } | Sets the value of this boolean property . |
12,943 | private JsonObject loadJson ( String fileName ) { URL url = cl . getResource ( fileName ) ; try { try ( Scanner scanner = new Scanner ( url . openStream ( ) , "UTF-8" ) . useDelimiter ( "\\A" ) ) { String json = scanner . next ( ) ; return new JsonObject ( json ) ; } catch ( NoSuchElementException e ) { throw new VertxException ( "Empty network configuration file." ) ; } catch ( DecodeException e ) { throw new VertxException ( "Invalid network configuration file." ) ; } } catch ( IOException e ) { throw new VertxException ( "Failed to read network configuration file." ) ; } } | Loads a network definition from a json network file . |
12,944 | static HazelcastInstance getHazelcastInstance ( Vertx vertx ) { VertxInternal vertxInternal = ( VertxInternal ) vertx ; ClusterManager clusterManager = vertxInternal . clusterManager ( ) ; if ( clusterManager != null ) { Class < ? > clazz = clusterManager . getClass ( ) ; Field field ; try { field = clazz . getDeclaredField ( "hazelcast" ) ; field . setAccessible ( true ) ; return HazelcastInstance . class . cast ( field . get ( clusterManager ) ) ; } catch ( Exception e ) { return null ; } } return null ; } | Returns the Vert . x Hazelcast instance if one exists . |
12,945 | public ClusterListener createClusterListener ( boolean localOnly ) { if ( localOnly ) return new NoClusterListener ( ) ; HazelcastInstance hazelcast = getHazelcastInstance ( vertx ) ; if ( hazelcast != null ) { return new HazelcastClusterListener ( hazelcast , vertx ) ; } else { return new NoClusterListener ( ) ; } } | Creates a cluster listener . |
12,946 | private void doFind ( final Message < JsonObject > message ) { String type = message . body ( ) . getString ( "type" ) ; if ( type != null ) { switch ( type ) { case "group" : doFindGroup ( message ) ; break ; case "node" : doFindNode ( message ) ; break ; case "network" : doFindNetwork ( message ) ; break ; default : message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid type specified." ) ) ; break ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No type specified." ) ) ; } } | Finds a node in the cluster . |
12,947 | private void doFindGroup ( final Message < JsonObject > message ) { String group = message . body ( ) . getString ( "group" ) ; if ( group == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid group name." ) ) ; return ; } final String address = String . format ( "%s.%s" , cluster , group ) ; context . execute ( new Action < Boolean > ( ) { public Boolean perform ( ) { return groups . containsKey ( address ) ; } } , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else if ( ! result . result ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid group." ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putString ( "result" , address ) ) ; } } } ) ; } | Finds a group in the cluster . |
12,948 | private void doFindNetwork ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "network" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No network name specified." ) ) ; } else { context . execute ( new Action < NetworkContext > ( ) { public NetworkContext perform ( ) { String scontext = data . < String , String > getMap ( String . format ( "%s.%s" , cluster , name ) ) . get ( String . format ( "%s.%s" , cluster , name ) ) ; if ( scontext != null ) { return Contexts . < NetworkContext > deserialize ( new JsonObject ( scontext ) ) ; } return null ; } } , new Handler < AsyncResult < NetworkContext > > ( ) { public void handle ( AsyncResult < NetworkContext > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else if ( result . result ( ) == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Not a valid network." ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putObject ( "result" , Contexts . serialize ( result . result ( ) ) ) ) ; } } } ) ; } } | Loads a network configuration . |
12,949 | private void doListGroup ( final Message < JsonObject > message ) { context . execute ( new Action < Set < String > > ( ) { public Set < String > perform ( ) { return groups . keySet ( ) ; } } , new Handler < AsyncResult < Set < String > > > ( ) { public void handle ( AsyncResult < Set < String > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putArray ( "result" , new JsonArray ( result . result ( ) . toArray ( new String [ result . result ( ) . size ( ) ] ) ) ) ) ; } } } ) ; } | Lists groups in the cluster . |
12,950 | private void doListNode ( final Message < JsonObject > message ) { context . execute ( new Action < Collection < String > > ( ) { public Collection < String > perform ( ) { List < String > nodes = new ArrayList < > ( ) ; for ( String group : groups . keySet ( ) ) { nodes . addAll ( groups . get ( group ) ) ; } return nodes ; } } , new Handler < AsyncResult < Collection < String > > > ( ) { public void handle ( AsyncResult < Collection < String > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putArray ( "result" , new JsonArray ( result . result ( ) . toArray ( new String [ result . result ( ) . size ( ) ] ) ) ) ) ; } } } ) ; } | Lists nodes in the cluster . |
12,951 | private void doListNetwork ( final Message < JsonObject > message ) { context . execute ( new Action < List < NetworkContext > > ( ) { public List < NetworkContext > perform ( ) { List < NetworkContext > contexts = new ArrayList < > ( ) ; for ( String name : networks ) { String scontext = data . < String , String > getMap ( String . format ( "%s.%s" , cluster , name ) ) . get ( String . format ( "%s.%s" , cluster , name ) ) ; if ( scontext != null ) { contexts . add ( Contexts . < NetworkContext > deserialize ( new JsonObject ( scontext ) ) ) ; } } return contexts ; } } , new Handler < AsyncResult < List < NetworkContext > > > ( ) { public void handle ( AsyncResult < List < NetworkContext > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { JsonArray contexts = new JsonArray ( ) ; for ( NetworkContext context : result . result ( ) ) { contexts . addObject ( Contexts . serialize ( context ) ) ; } message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putArray ( "result" , contexts ) ) ; } } } ) ; } | Lists the networks running in the cluster . |
12,952 | private void doSelect ( final Message < JsonObject > message ) { String type = message . body ( ) . getString ( "type" ) ; if ( type != null ) { switch ( type ) { case "group" : doSelectGroup ( message ) ; break ; case "node" : doSelectNode ( message ) ; break ; default : message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid type specified." ) ) ; break ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No type specified." ) ) ; } } | Selects an object in the cluster . |
12,953 | private void selectNode ( final Object key , final Handler < AsyncResult < String > > doneHandler ) { context . execute ( new Action < String > ( ) { public String perform ( ) { String address = nodeSelectors . get ( key ) ; if ( address != null ) { return address ; } Set < String > nodes = new HashSet < > ( ) ; for ( String group : groups . keySet ( ) ) { nodes . addAll ( groups . get ( group ) ) ; } int index = new Random ( ) . nextInt ( nodes . size ( ) ) ; int i = 0 ; for ( String node : nodes ) { if ( i == index ) { nodeSelectors . put ( key , node ) ; return node ; } i ++ ; } return null ; } } , doneHandler ) ; } | Selects a node . |
12,954 | private Handler < AsyncResult < String > > createDeploymentHandler ( final Message < JsonObject > message ) { return new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { addNewDeployment ( result . result ( ) , message . body ( ) , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putString ( "id" , result . result ( ) ) ) ; } } ) ; } } } ; } | Creates a platform deployment handler . |
12,955 | private Handler < AsyncResult < String > > createRedeployHandler ( final JsonObject deploymentInfo , final CountDownLatch latch ) { return new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . failed ( ) ) { log . error ( result . cause ( ) ) ; latch . countDown ( ) ; } else { addMappedDeployment ( result . result ( ) , deploymentInfo , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { latch . countDown ( ) ; } } ) ; } } } ; } | Creates a redeploy handler . |
12,956 | private void findDeploymentAddress ( final String deploymentID , Handler < AsyncResult < String > > resultHandler ) { context . execute ( new Action < String > ( ) { public String perform ( ) { synchronized ( deployments ) { JsonObject locatedInfo = null ; Collection < String > sdeploymentsInfo = deployments . get ( cluster ) ; for ( String sdeploymentInfo : sdeploymentsInfo ) { JsonObject deploymentInfo = new JsonObject ( sdeploymentInfo ) ; if ( deploymentInfo . getString ( "id" ) . equals ( deploymentID ) ) { locatedInfo = deploymentInfo ; break ; } } if ( locatedInfo != null ) { return locatedInfo . getString ( "address" ) ; } return null ; } } } , resultHandler ) ; } | Locates the internal address of the node on which a deployment is deployed . |
12,957 | private Handler < AsyncResult < Void > > createUndeployHandler ( final Message < JsonObject > message ) { return new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) ) ; } } } ; } | Creates a platform undeploy handler . |
12,958 | private void removeDeployment ( final String deploymentID , Handler < AsyncResult < String > > doneHandler ) { context . execute ( new Action < String > ( ) { public String perform ( ) { Collection < String > clusterDeployments = deployments . get ( cluster ) ; if ( clusterDeployments != null ) { String deployment = null ; for ( String sdeployment : clusterDeployments ) { JsonObject info = new JsonObject ( sdeployment ) ; if ( info . getString ( "id" ) . equals ( deploymentID ) ) { deployment = sdeployment ; break ; } } if ( deployment != null ) { deployments . remove ( cluster , deployment ) ; return new JsonObject ( deployment ) . getString ( "realID" ) ; } } return null ; } } , doneHandler ) ; } | Removes a deployment from the deployments map and returns the real deploymentID . |
12,959 | private void doUndeployNetwork ( final Message < JsonObject > message ) { Object network = message . body ( ) . getValue ( "network" ) ; if ( network != null ) { String key ; if ( network instanceof String ) { key = ( String ) network ; } else if ( network instanceof JsonObject ) { try { key = serializer . deserializeObject ( ( JsonObject ) network , NetworkConfig . class ) . getName ( ) ; } catch ( SerializationException e ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , e . getMessage ( ) ) ) ; return ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid network configuration." ) ) ; return ; } selectNode ( key , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else if ( result . result ( ) == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No nodes available." ) ) ; } else { vertx . eventBus ( ) . sendWithTimeout ( result . result ( ) , message . body ( ) , 120000 , new Handler < AsyncResult < Message < JsonObject > > > ( ) { public void handle ( AsyncResult < Message < JsonObject > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Failed to reach node." ) ) ; } else { message . reply ( result . result ( ) . body ( ) ) ; } } } ) ; } } } ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No network specified." ) ) ; } } | Undeploys a network . |
12,960 | private void doKeySet ( final Message < JsonObject > message ) { final String key = message . body ( ) . getString ( "name" ) ; if ( key == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No key specified." ) ) ; return ; } final Object value = message . body ( ) . getValue ( "value" ) ; context . execute ( new Action < Void > ( ) { public Void perform ( ) { data . getMap ( formatKey ( "keys" ) ) . put ( key , value ) ; return null ; } } , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) ) ; } } } ) ; } | Handles setting a key . |
12,961 | private void doCounterGet ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } context . execute ( new Action < Long > ( ) { public Long perform ( ) { Map < Object , Long > counters = data . getMap ( formatKey ( "counters" ) ) ; Long value = counters . get ( name ) ; if ( value == null ) { value = 0L ; } return value ; } } , new Handler < AsyncResult < Long > > ( ) { public void handle ( AsyncResult < Long > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putNumber ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles getting a counter . |
12,962 | private void doMultiMapRemove ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } final Object key = message . body ( ) . getValue ( "key" ) ; if ( key == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No key specified." ) ) ; return ; } final Object value = message . body ( ) . getValue ( "value" ) ; if ( value != null ) { context . execute ( new Action < Boolean > ( ) { public Boolean perform ( ) { return data . getMultiMap ( formatKey ( name ) ) . remove ( key , value ) ; } } , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , result . result ( ) ) ) ; } } } ) ; } else { context . execute ( new Action < Collection < Object > > ( ) { public Collection < Object > perform ( ) { return data . getMultiMap ( formatKey ( name ) ) . remove ( key ) ; } } , new Handler < AsyncResult < Collection < Object > > > ( ) { public void handle ( AsyncResult < Collection < Object > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putArray ( "result" , new JsonArray ( result . result ( ) . toArray ( new Object [ result . result ( ) . size ( ) ] ) ) ) ) ; } } } ) ; } } | Handles a cluster multi - map remove command . |
12,963 | private void doMultiMapKeys ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } context . execute ( new Action < Set < Object > > ( ) { public Set < Object > perform ( ) { return data . getMultiMap ( formatKey ( name ) ) . keySet ( ) ; } } , new Handler < AsyncResult < Set < Object > > > ( ) { public void handle ( AsyncResult < Set < Object > > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putArray ( "result" , new JsonArray ( result . result ( ) . toArray ( new Object [ result . result ( ) . size ( ) ] ) ) ) ) ; } } } ) ; } | Handles a cluster multi - map keys command . |
12,964 | private void doMapPut ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } final Object key = message . body ( ) . getValue ( "key" ) ; if ( key == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No key specified." ) ) ; return ; } final Object value = message . body ( ) . getValue ( "value" ) ; if ( value == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No value specified." ) ) ; return ; } context . execute ( new Action < Object > ( ) { public Object perform ( ) { return data . getMap ( formatKey ( name ) ) . put ( key , value ) ; } } , new Handler < AsyncResult < Object > > ( ) { public void handle ( AsyncResult < Object > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putValue ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles a cluster map put command . |
12,965 | private void doListGet ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } final Integer index = message . body ( ) . getInteger ( "index" ) ; if ( index == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No index specified." ) ) ; return ; } context . execute ( new Action < Object > ( ) { public Object perform ( ) { return data . getList ( formatKey ( name ) ) . get ( index ) ; } } , new Handler < AsyncResult < Object > > ( ) { public void handle ( AsyncResult < Object > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putValue ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles a list get . |
12,966 | private void doListRemove ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } if ( message . body ( ) . containsField ( "index" ) ) { final int index = message . body ( ) . getInteger ( "index" ) ; context . execute ( new Action < Object > ( ) { public Object perform ( ) { return data . getList ( formatKey ( name ) ) . remove ( index ) ; } } , new Handler < AsyncResult < Object > > ( ) { public void handle ( AsyncResult < Object > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putValue ( "result" , result . result ( ) ) ) ; } } } ) ; } else { final Object value = message . body ( ) . getValue ( "value" ) ; if ( value == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No value specified." ) ) ; } else { context . execute ( new Action < Boolean > ( ) { public Boolean perform ( ) { return data . getList ( formatKey ( name ) ) . remove ( value ) ; } } , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , result . result ( ) ) ) ; } } } ) ; } } } | Handles a list removal . |
12,967 | private void doQueueIsEmpty ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } context . execute ( new Action < Boolean > ( ) { public Boolean perform ( ) { return data . getQueue ( formatKey ( name ) ) . isEmpty ( ) ; } } , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles cluster queue is empty command . |
12,968 | private void doQueueClear ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } context . execute ( new Action < Void > ( ) { public Void perform ( ) { data . getQueue ( formatKey ( name ) ) . clear ( ) ; return null ; } } , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) ) ; } } } ) ; } | Clears all items in a queue . |
12,969 | private void doQueueOffer ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } final Object value = message . body ( ) . getValue ( "value" ) ; if ( value == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No value specified." ) ) ; return ; } context . execute ( new Action < Boolean > ( ) { public Boolean perform ( ) { return data . getQueue ( formatKey ( name ) ) . offer ( value ) ; } } , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles a queue offer command . |
12,970 | private void doQueueElement ( final Message < JsonObject > message ) { final String name = message . body ( ) . getString ( "name" ) ; if ( name == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No name specified." ) ) ; return ; } context . execute ( new Action < Object > ( ) { public Object perform ( ) { return data . getQueue ( formatKey ( name ) ) . element ( ) ; } } , new Handler < AsyncResult < Object > > ( ) { public void handle ( AsyncResult < Object > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putValue ( "result" , result . result ( ) ) ) ; } } } ) ; } | Handles a queue element command . |
12,971 | public Integer getInstance ( ) { try { return Integer . valueOf ( uri . getPath ( ) . split ( "/" ) [ 2 ] ) ; } catch ( IndexOutOfBoundsException e ) { return null ; } } | Returns the instance number . |
12,972 | public String getEndpoint ( ) { try { String endpointString = uri . getPath ( ) . split ( "/" ) [ 3 ] ; if ( ! endpointString . equals ( ENDPOINT_IN ) && ! endpointString . equals ( ENDPOINT_OUT ) ) { throw new IllegalArgumentException ( endpointString + " is not a valid context endpoint" ) ; } return endpointString ; } catch ( IndexOutOfBoundsException e ) { return null ; } } | Returns the context endpoint type . |
12,973 | public Map < String , String > getQuery ( ) { String query = uri . getQuery ( ) ; String [ ] pairs = query . split ( "&" ) ; Map < String , String > args = new HashMap < > ( ) ; for ( String pair : pairs ) { int idx = pair . indexOf ( "=" ) ; try { args . put ( URLDecoder . decode ( pair . substring ( 0 , idx ) , "UTF-8" ) , URLDecoder . decode ( pair . substring ( idx + 1 ) , "UTF-8" ) ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( e ) ; } } return args ; } | Returns a map of all query arguments . |
12,974 | @ SuppressWarnings ( "unchecked" ) public < T > T getQuery ( String name ) { return ( T ) getQuery ( ) . get ( name ) ; } | Returns a specific query argument . |
12,975 | protected String getInternal ( String defaultValue , boolean required ) { String value = properties . getProperty ( path , defaultValue ) ; if ( value != null ) { return value ; } if ( defaultValue == null ) { value = getDefaultValue ( ) ; if ( value != null ) { return value ; } } if ( required ) { throw new RuntimeException ( "Property " + path + " must be set" ) ; } return value ; } | Retrieves the value of a property using a given default value and optionally failing if there is no value . |
12,976 | public void onChange ( String oldValue , String value ) { if ( TriggerableProperties . equals ( oldValue , value ) ) { return ; } triggerList . execute ( this , value ) ; } | Called when a property s value has just changed . |
12,977 | public boolean booleanValue ( ) { final String value = getInternal ( null , false ) ; if ( value == null ) { return false ; } return toBoolean ( value ) ; } | Returns the boolean value of this property . |
12,978 | public static boolean toBoolean ( final String value ) { String trimmedLowerValue = value . toLowerCase ( ) . trim ( ) ; return trimmedLowerValue . equals ( "1" ) || trimmedLowerValue . equals ( "true" ) || trimmedLowerValue . equals ( "yes" ) ; } | Converts a string to a boolean . |
12,979 | public double get ( ) { final String value = getInternal ( null , false ) ; if ( value == null ) { return noValue ( ) ; } double v = Double . parseDouble ( value ) ; return limit ( v ) ; } | Retrieves the value of this double property according to these rules . |
12,980 | public ClusterData createClusterData ( boolean localOnly ) { if ( localOnly ) return new VertxClusterData ( vertx ) ; HazelcastInstance hazelcast = ClusterListenerFactory . getHazelcastInstance ( vertx ) ; if ( hazelcast != null ) { return new HazelcastClusterData ( hazelcast ) ; } else { return new VertxClusterData ( vertx ) ; } } | Creates cluster data . |
12,981 | public Object deserialize ( JsonObject message ) { String type = message . getString ( "type" ) ; if ( type == null ) { return message . getValue ( "value" ) ; } else { switch ( type ) { case "buffer" : return new Buffer ( message . getBinary ( "value" ) ) ; case "bytes" : return message . getBinary ( "value" ) ; case "serialized" : byte [ ] bytes = message . getBinary ( "value" ) ; ObjectInputStream stream = null ; try { stream = new ThreadObjectInputStream ( new ByteArrayInputStream ( bytes ) ) ; return stream . readObject ( ) ; } catch ( ClassNotFoundException | IOException e ) { throw new SerializationException ( e . getMessage ( ) ) ; } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( IOException e ) { } } } default : return message . getValue ( "value" ) ; } } } | Deserializes an input message . |
12,982 | public int get ( ) { final String value = getInternal ( null , false ) ; if ( value == null ) { return noValue ( ) ; } int v = Integer . parseInt ( value ) ; return limit ( v ) ; } | Retrieves the value of this integer property according to these rules . |
12,983 | public Property getPropertyDefinition ( String path ) { final List propertyList = getPropertyList ( ) ; for ( int i = 0 ; i < propertyList . size ( ) ; i ++ ) { Property property = ( Property ) propertyList . get ( i ) ; if ( property . getPath ( ) . equals ( path ) ) { return property ; } } return null ; } | Returns the definition of a named property or null if there is no such property . |
12,984 | private void clearDeployments ( final Handler < AsyncResult < Void > > doneHandler ) { context . execute ( new Action < Void > ( ) { public Void perform ( ) { Collection < String > sdeploymentsInfo = deployments . get ( group ) ; for ( String sdeploymentInfo : sdeploymentsInfo ) { JsonObject deploymentInfo = new JsonObject ( sdeploymentInfo ) ; if ( deploymentInfo . getString ( "address" ) . equals ( internal ) ) { deployments . remove ( group , sdeploymentInfo ) ; } } return null ; } } , doneHandler ) ; } | When the cluster is shutdown properly we need to remove deployments from the deployments map in order to ensure that deployments aren t redeployed if this node leaves the cluster . |
12,985 | private void doList ( final Message < JsonObject > message ) { String type = message . body ( ) . getString ( "type" ) ; if ( type != null ) { switch ( type ) { case "node" : doListNode ( message ) ; break ; default : message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid type specified." ) ) ; break ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No type specified." ) ) ; } } | Lists objects in the group . |
12,986 | private void doSelectNode ( final Message < JsonObject > message ) { final Object key = message . body ( ) . getValue ( "key" ) ; if ( key == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No key specified." ) ) ; } else { context . execute ( new Action < String > ( ) { public String perform ( ) { String address = nodeSelectors . get ( key ) ; if ( address != null ) { return address ; } Collection < String > nodes = groups . get ( group ) ; int index = new Random ( ) . nextInt ( nodes . size ( ) ) ; int i = 0 ; for ( String node : nodes ) { if ( i == index ) { nodeSelectors . put ( key , node ) ; return node ; } i ++ ; } return null ; } } , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else if ( result . result ( ) == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No nodes to select." ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putString ( "result" , result . result ( ) ) ) ; } } } ) ; } } | Selects a node in the group . |
12,987 | private void doDeploy ( final Message < JsonObject > message ) { String type = message . body ( ) . getString ( "type" ) ; if ( type == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No deployment type specified." ) ) ; } else { switch ( type ) { case "module" : doDeployModule ( message ) ; break ; case "verticle" : doDeployVerticle ( message ) ; break ; default : message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid deployment type." ) ) ; break ; } } } | Deploys a module or verticle . |
12,988 | private void addNewDeployment ( final String deploymentID , final JsonObject deploymentInfo , Handler < AsyncResult < String > > doneHandler ) { context . execute ( new Action < String > ( ) { public String perform ( ) { deployments . put ( group , deploymentInfo . copy ( ) . putString ( "id" , deploymentID ) . putString ( "realID" , deploymentID ) . putString ( "address" , internal ) . putString ( "node" , listener . nodeId ( ) ) . encode ( ) ) ; return deploymentID ; } } , doneHandler ) ; } | Adds a deployment to the cluster deployments map . |
12,989 | private void doRedeploy ( final JsonObject deploymentInfo ) { if ( deploymentInfo . getString ( "type" ) . equals ( "module" ) ) { log . info ( String . format ( "%s - redeploying module %s" , DefaultGroupManager . this , deploymentInfo . getString ( "module" ) ) ) ; final CountDownLatch latch = new CountDownLatch ( 1 ) ; platform . deployModule ( deploymentInfo . getString ( "module" ) , deploymentInfo . getObject ( "config" , new JsonObject ( ) ) , deploymentInfo . getInteger ( "instances" , 1 ) , createRedeployHandler ( deploymentInfo , latch ) ) ; try { latch . await ( 10 , TimeUnit . SECONDS ) ; } catch ( InterruptedException e ) { } } else if ( deploymentInfo . getString ( "type" ) . equals ( "verticle" ) ) { log . info ( String . format ( "%s - redeploying verticle %s" , DefaultGroupManager . this , deploymentInfo . getString ( "main" ) ) ) ; final CountDownLatch latch = new CountDownLatch ( 1 ) ; if ( deploymentInfo . getBoolean ( "worker" , false ) ) { platform . deployWorkerVerticle ( deploymentInfo . getString ( "main" ) , deploymentInfo . getObject ( "config" , new JsonObject ( ) ) , deploymentInfo . getInteger ( "instances" , 1 ) , deploymentInfo . getBoolean ( "multi-threaded" ) , createRedeployHandler ( deploymentInfo , latch ) ) ; } else { platform . deployVerticle ( deploymentInfo . getString ( "main" ) , deploymentInfo . getObject ( "config" , new JsonObject ( ) ) , deploymentInfo . getInteger ( "instances" , 1 ) , createRedeployHandler ( deploymentInfo , latch ) ) ; } try { latch . await ( 10 , TimeUnit . SECONDS ) ; } catch ( InterruptedException e ) { } } } | Redeploys a deployment . |
12,990 | public void runTask ( Handler < Task > task ) { if ( currentTask == null ) { currentTask = new Task ( this ) ; task . handle ( currentTask ) ; } else { queue . add ( task ) ; } } | Runs a sequential task . |
12,991 | private void checkTasks ( ) { if ( currentTask == null ) { Handler < Task > task = queue . poll ( ) ; if ( task != null ) { currentTask = new Task ( this ) ; task . handle ( currentTask ) ; } } } | Starts the next task if necessary . |
12,992 | private void doInstalled ( final Message < JsonObject > message ) { String moduleName = message . body ( ) . getString ( "module" ) ; if ( moduleName == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No module specified." ) ) ; return ; } platform . getModuleInfo ( moduleName , new Handler < AsyncResult < ModuleInfo > > ( ) { public void handle ( AsyncResult < ModuleInfo > result ) { if ( result . failed ( ) || result . result ( ) == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , false ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putBoolean ( "result" , true ) ) ; } } } ) ; } | Checks if a module is installed . |
12,993 | private void doInstall ( final Message < JsonObject > message ) { String moduleName = message . body ( ) . getString ( "module" ) ; if ( moduleName == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No module specified." ) ) ; return ; } String uploadID = message . body ( ) . getString ( "upload" ) ; if ( uploadID == null ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No upload found." ) ) ; return ; } final File modRoot = new File ( TEMP_DIR , "vertx-zip-mods" ) ; final File modZip = new File ( modRoot , uploadID + ".zip" ) ; vertx . fileSystem ( ) . exists ( modZip . getAbsolutePath ( ) , new Handler < AsyncResult < Boolean > > ( ) { public void handle ( AsyncResult < Boolean > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else if ( ! result . result ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid upload." ) ) ; } else { platform . installModule ( modZip . getAbsolutePath ( ) , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) ) ; } } } ) ; } } } ) ; } | Installs a module . |
12,994 | private void doDeployNetwork ( final Message < JsonObject > message ) { Object network = message . body ( ) . getValue ( "network" ) ; if ( network != null ) { if ( network instanceof String ) { doDeployNetwork ( ( String ) network , message ) ; } else if ( network instanceof JsonObject ) { JsonObject jsonNetwork = ( JsonObject ) network ; try { NetworkConfig config = serializer . deserializeObject ( jsonNetwork , NetworkConfig . class ) ; doDeployNetwork ( config , message ) ; } catch ( SerializationException e ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , e . getMessage ( ) ) ) ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Invalid network configuration." ) ) ; } } else { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "No network specified." ) ) ; } } | Deploys a network . |
12,995 | private void doDeployNetwork ( final String name , final Message < JsonObject > message ) { String scontext = data . < String , String > getMap ( String . format ( "%s.%s" , cluster , name ) ) . get ( String . format ( "%s.%s" , cluster , name ) ) ; final NetworkContext context = scontext != null ? Contexts . < NetworkContext > deserialize ( new JsonObject ( scontext ) ) : ContextBuilder . buildContext ( new DefaultNetworkConfig ( name ) , cluster ) ; if ( ! managers . containsKey ( context . address ( ) ) ) { platform . deployVerticle ( NetworkManager . class . getName ( ) , new JsonObject ( ) . putString ( "cluster" , cluster ) . putString ( "address" , context . address ( ) ) , 1 , new Handler < AsyncResult < String > > ( ) { public void handle ( AsyncResult < String > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , "Failed to deploy network manager." ) ) ; } else { final String deploymentID = result . result ( ) ; DefaultNodeManager . this . context . execute ( new Action < Void > ( ) { public Void perform ( ) { networks . add ( context . name ( ) ) ; return null ; } } , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { managers . put ( context . address ( ) , deploymentID ) ; doDeployNetwork ( context , message ) ; } } ) ; } } } ) ; } else { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putObject ( "context" , Contexts . serialize ( context ) ) ) ; } } | Deploys a network from name . |
12,996 | private void doDeployNetwork ( final NetworkContext context , final Message < JsonObject > message ) { final WrappedWatchableMap < String , String > data = new WrappedWatchableMap < String , String > ( context . address ( ) , this . data . < String , String > getMap ( context . address ( ) ) , vertx ) ; data . watch ( context . status ( ) , null , new Handler < MapEvent < String , String > > ( ) { public void handle ( MapEvent < String , String > event ) { if ( event . type ( ) . equals ( MapEvent . Type . CREATE ) && event . value ( ) . equals ( context . version ( ) ) ) { data . unwatch ( context . status ( ) , null , this , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { message . reply ( new JsonObject ( ) . putString ( "status" , "ok" ) . putObject ( "context" , Contexts . serialize ( context ) ) ) ; } } ) ; } } } , new Handler < AsyncResult < Void > > ( ) { public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , result . cause ( ) . getMessage ( ) ) ) ; } else { try { data . put ( context . address ( ) , Contexts . serialize ( context ) . encode ( ) ) ; } catch ( Exception e ) { message . reply ( new JsonObject ( ) . putString ( "status" , "error" ) . putString ( "message" , e . getMessage ( ) ) ) ; } } } } ) ; } | Deploys a network from context . |
12,997 | private void removeDeployment ( final String deploymentID , Handler < AsyncResult < Void > > doneHandler ) { context . execute ( new Action < Void > ( ) { public Void perform ( ) { Collection < String > nodeDeployments = deployments . get ( node ) ; if ( nodeDeployments != null ) { String deployment = null ; for ( String sdeployment : nodeDeployments ) { JsonObject info = new JsonObject ( sdeployment ) ; if ( info . getString ( "id" ) . equals ( deploymentID ) ) { deployment = sdeployment ; break ; } } if ( deployment != null ) { deployments . remove ( node , deployment ) ; } } return null ; } } , doneHandler ) ; } | Removes a deployment from the deployments map . |
12,998 | @ SuppressWarnings ( "WeakerAccess" ) public SnackbarWrapper addCallbacks ( List < Callback > callbacks ) { int callbacksSize = callbacks . size ( ) ; for ( int i = 0 ; i < callbacksSize ; i ++ ) { addCallback ( callbacks . get ( i ) ) ; } return this ; } | Adds multiple callbacks to the Snackbar for various events . |
12,999 | private boolean isSerializableType ( Class < ? > type ) { Boolean serializable = cache . get ( type ) ; if ( serializable != null ) { return serializable ; } if ( type == Object . class ) { return true ; } if ( primitiveTypes . contains ( type ) ) { cache . put ( type , true ) ; return true ; } if ( JsonSerializable . class . isAssignableFrom ( type ) ) { cache . put ( type , true ) ; return true ; } for ( Class < ? > clazz : serializableTypes ) { if ( clazz . isAssignableFrom ( type ) ) { cache . put ( type , true ) ; return true ; } } cache . put ( type , false ) ; return false ; } | Indicates whether the given type is a serializable type . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.