Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Apr 20, 2021
2 parents 1ab1e72 + 4bcad51 commit ac6df76
Show file tree
Hide file tree
Showing 46 changed files with 6,176 additions and 1,566 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# OS + IDE
.DS_Store
/settings.xml
.project
.settings/
.vscode

# Testing Logs
test-harness/logs/*.log
Expand Down
42 changes: 0 additions & 42 deletions .jsbeautifyrc

This file was deleted.

12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"cfml.mappings": [
{
"logicalPath": "/coldbox",
"directoryPath": "."
},
{
"logicalPath": "/testbox",
"directoryPath": "./testbox"
}
]
}
33 changes: 33 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run CommandBox Task",
"type": "shell",
"command": "box task run ${relativeFile}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
},
{
"label": "Run CommandBox Task",
"type": "shell",
"command": "box testbox run bundles=${relativeFile}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": []
}
]
}
102 changes: 80 additions & 22 deletions system/async/AsyncManager.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,36 @@
*/
component accessors="true" singleton {

/**
* --------------------------------------------------------------------------
* Properties
* --------------------------------------------------------------------------
*/

/**
* A collection of executors you can register in the async manager
* so you can run queues, tasks or even scheduled tasks
*/
property name="executors" type="struct";

// Static class to Executors: java.util.concurrent.Executors
this.$executors = new util.Executors();
/**
* This scheduler can be linked to a ColdBox context
*/
property name="coldbox";

// Helpers
variables.IntStream = createObject( "java", "java.util.stream.IntStream" );
// Static class to Executors: java.util.concurrent.Executors
this.$executors = new coldbox.system.async.executors.ExecutorBuilder();

/**
* Constructor
*
* @debug Add debugging logs to System out, disabled by default
*/
AsyncManager function init( boolean debug = false ){
variables.debug = arguments.debug;
variables.System = createObject( "java", "java.lang.System" );
variables.debug = arguments.debug;

// Build out our executors map
variables.executors = {};

return this;
Expand Down Expand Up @@ -66,7 +77,7 @@ component accessors="true" singleton {
* @debug Add output debugging
* @loadAppContext Load the CFML App contexts or not, disable if not used
*
* @return The ColdBox Schedule class to work with the schedule: coldbox.system.async.tasks.Executor
* @return The ColdBox Schedule class to work with the schedule: coldbox.system.async.executors.Executor
*/
Executor function newExecutor(
required name,
Expand Down Expand Up @@ -106,22 +117,21 @@ component accessors="true" singleton {
switch ( arguments.type ) {
case "fixed": {
arguments.executor = this.$executors.newFixedThreadPool( arguments.threads );
return new tasks.Executor( argumentCollection = arguments );
return new executors.Executor( argumentCollection = arguments );
}
case "cached": {
arguments.executor = this.$executors.newCachedThreadPool();
return new tasks.Executor( argumentCollection = arguments );
return new executors.Executor( argumentCollection = arguments );
}
case "single": {
arguments.executor = this.$executors.newFixedThreadPool( 1 );
return new tasks.Executor( argumentCollection = arguments );
return new executors.Executor( argumentCollection = arguments );
}
case "scheduled": {
arguments.executor = this.$executors.newScheduledThreadPool( arguments.threads );
return new tasks.ScheduledExecutor( argumentCollection = arguments );
return new executors.ScheduledExecutor( argumentCollection = arguments );
}
default : {

default: {
}
}
throw(
Expand Down Expand Up @@ -175,7 +185,7 @@ component accessors="true" singleton {
* @name The executor name
*
* @throws ExecutorNotFoundException
* @return The executor object: coldbox.system.async.tasks.Executor
* @return The executor object: coldbox.system.async.executors.Executor
*/
Executor function getExecutor( required name ){
if ( hasExecutor( arguments.name ) ) {
Expand Down Expand Up @@ -295,7 +305,7 @@ component accessors="true" singleton {
boolean debug = false,
boolean loadAppContext = true
){
return new Future( argumentCollection = arguments );
return new tasks.Future( argumentCollection = arguments );
}

/**
Expand All @@ -312,7 +322,7 @@ component accessors="true" singleton {
boolean debug = false,
boolean loadAppContext = true
){
return new Future( argumentCollection = arguments );
return new tasks.Future( argumentCollection = arguments );
}

/****************************************************************
Expand Down Expand Up @@ -344,6 +354,31 @@ component accessors="true" singleton {
* Utilities *
****************************************************************/

/**
* Build out a scheduler object for usage within this async manager context and return it to you.
* You must manage it's persistence, we only wire it and create it for you so you can use it
* to schedule tasks.
*
* @name The unique name for the scheduler
*/
Scheduler function newScheduler( required name ){
return new coldbox.system.async.tasks.Scheduler( arguments.name, this );
}

/**
* Build out a new Duration class
*/
Duration function duration(){
return new time.Duration( argumentCollection = arguments );
}

/**
* Build out a new Period class
*/
Period function period(){
return new time.Period( argumentCollection = arguments );
}

/**
* Build an array out of a range of numbers or using our range syntax.
* You can also build negative ranges
Expand All @@ -357,22 +392,45 @@ component accessors="true" singleton {
* @from The initial index, defaults to 1 or you can use the {start}..{end} notation
* @to The last index item
*/
array function arrayRange( any from=1, numeric to ){
array function arrayRange( any from = 1, numeric to ){
// shortcut notation
if( find( "..", arguments.from ) ){
arguments.to = getToken( arguments.from, 2, ".." );
arguments.from = getToken( arguments.from, 1, ".." );
if ( find( "..", arguments.from ) ) {
arguments.to = getToken( arguments.from, 2, ".." );
arguments.from = getToken( arguments.from, 1, ".." );
}

// cap to if larger than from
if( arguments.to < arguments.from ){
if ( arguments.to < arguments.from ) {
arguments.to = arguments.from;
}

// build it up
return IntStream
var javaArray = createObject( "java", "java.util.stream.IntStream" )
.rangeClosed( arguments.from, arguments.to )
.toArray();
var cfArray = [];
cfArray.append( javaArray, true );
return cfArray;
}

/**
* Utility to send to output to the output stream
*
* @var Variable/Message to send
*/
AsyncManager function out( required var ){
variables.System.out.println( arguments.var.toString() );
return this;
}

/**
* Utility to send to output to the error stream
*
* @var Variable/Message to send
*/
AsyncManager function err( required var ){
variables.System.err.println( arguments.var.toString() );
return this;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ component accessors="true" singleton {
property name="native";

// Prepare the static time unit class
this.$timeUnit = new coldbox.system.async.util.TimeUnit();
this.$timeUnit = new coldbox.system.async.time.TimeUnit();

/**
* Constructor
Expand Down Expand Up @@ -71,7 +71,7 @@ component accessors="true" singleton {
);

// Send for execution
return new FutureTask( variables.native.submit( jCallable ) );
return new coldbox.system.async.tasks.FutureTask( variables.native.submit( jCallable ) );
}

/****************************************************************
Expand Down
File renamed without changes.
Loading

0 comments on commit ac6df76

Please sign in to comment.