Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright © 2013 Keith Webster Johnston. | ||
* All rights reserved. | ||
* | ||
* This file is part of avalanche. | ||
* | ||
* avalanche is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* avalanche is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with avalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*---------------------------------------------------------------------------*/ | ||
package com.johnstok.avalanche; | ||
|
||
|
||
/** | ||
* A callback for notifying events related to an item of work. | ||
* | ||
* @author Keith Webster Johnston. | ||
*/ | ||
public interface Callback { | ||
|
||
void onComplete(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright © 2013 Keith Webster Johnston. | ||
* All rights reserved. | ||
* | ||
* This file is part of avalanche. | ||
* | ||
* avalanche is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* avalanche is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with avalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*---------------------------------------------------------------------------*/ | ||
package com.johnstok.avalanche; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
|
||
/** | ||
* A generator generates work. | ||
* | ||
* @param <T> | ||
* | ||
* @author Keith Webster Johnston. | ||
*/ | ||
public interface Generator<T> { | ||
|
||
Future<T> generate(Callback callback); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/java/main/com/johnstok/avalanche/GeneratorRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright © 2013 Keith Webster Johnston. | ||
* All rights reserved. | ||
* | ||
* This file is part of avalanche. | ||
* | ||
* avalanche is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* avalanche is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with avalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*---------------------------------------------------------------------------*/ | ||
package com.johnstok.avalanche; | ||
|
||
|
||
public class GeneratorRunnable<T> implements Runnable { | ||
|
||
private final Generator<T> _generator; | ||
private final Callback _callback; | ||
|
||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param generator | ||
* @param callback | ||
*/ | ||
public GeneratorRunnable(final Generator<T> generator, | ||
final Callback callback) { | ||
_generator = generator; | ||
_callback = callback; | ||
} | ||
|
||
|
||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void run() { | ||
_generator.generate(_callback); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright © 2013 Keith Webster Johnston. | ||
* All rights reserved. | ||
* | ||
* This file is part of avalanche. | ||
* | ||
* avalanche is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* avalanche is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with avalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*---------------------------------------------------------------------------*/ | ||
package com.johnstok.avalanche; | ||
|
||
|
||
/** | ||
* A callback with no action. | ||
* | ||
* @author Keith Webster Johnston. | ||
*/ | ||
public class NoOpCallback | ||
implements | ||
Callback { | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void onComplete() { /* No Op. */ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*----------------------------------------------------------------------------- | ||
* Copyright © 2013 Keith Webster Johnston. | ||
* All rights reserved. | ||
* | ||
* This file is part of avalanche. | ||
* | ||
* avalanche is free software: you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* avalanche is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with avalanche. If not, see <http://www.gnu.org/licenses/>. | ||
*---------------------------------------------------------------------------*/ | ||
package com.johnstok.avalanche; | ||
|
||
|
||
import java.util.concurrent.Future; | ||
|
||
|
||
/** | ||
* A pattern of requests emitted via a generator. | ||
* | ||
* @author Keith Webster Johnston. | ||
*/ | ||
public interface Workload { | ||
|
||
Future<Void> execute(Generator<Void> command); | ||
|
||
} |