You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Thomas Vandahl <tv...@apache.org> on 2019/03/03 18:38:22 UTC
Change modules to interfaces
Hi folks,
I finally found the time to try something I planned to do for Turbine
4.0 already. I changed all modules (Action, Page, Screen,...) to be
(functional) interfaces instead of base classes. This works fine but
results in some methods to be public that were protected before.
The advantage is that the whole module and loader code is much cleaner
and simpler now and less spread over the different classes.
Before I commit this, I wanted to ask if any of your code heavily relies
on the old behavior?
Bye, Thomas
Example for Action:
--8<--
@FunctionalInterface
public interface Action extends Assembler
{
/** Prefix for action related classes and templates */
String PREFIX = "actions";
/** Property for the size of the module cache if caching is on */
String CACHE_SIZE_KEY = "action.cache.size";
/** The default size for the action cache */
int CACHE_SIZE_DEFAULT = 20;
/** Represents Action Objects */
String NAME = "action";
/**
* A subclass must implement this method to perform itself. The
* Action can also set the screen that is associated with {@link
PipelineData}.
*
* @param pipelineData Turbine information.
* @throws Exception a generic exception.
*/
void doPerform(PipelineData pipelineData) throws Exception;
/**
* Subclasses can override this method to add additional
* functionality.
*
* @param pipelineData Turbine information.
* @throws Exception a generic exception.
*/
default void perform(PipelineData pipelineData) throws Exception
{
doPerform(pipelineData);
}
}
--8<--
Example for ActionLoader:
--8<--
public class ActionLoader
extends GenericLoader<Action>
{
/** The single instance of this class. */
private static ActionLoader instance = new ActionLoader();
/**
* These ctor's are private to force clients to use getInstance()
* to access this class.
*/
private ActionLoader()
{
super(Action.class,
() -> Turbine.getConfiguration().getInt(Action.CACHE_SIZE_KEY,
Action.CACHE_SIZE_DEFAULT));
}
/**
* Attempts to load and execute the external action.
*
* @param pipelineData Turbine information.
* @param name Name of object that will execute the action.
* @throws Exception a generic exception.
*/
@Override
public void exec(PipelineData pipelineData, String name)
throws Exception
{
getAssembler(name).perform(pipelineData);
}
/**
* The method through which this class is accessed.
*
* @return The single instance of this class.
*/
public static ActionLoader getInstance()
{
return instance;
}
}
--8<--
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
For additional commands, e-mail: dev-help@turbine.apache.org
Re: Re: Change modules to interfaces
Posted by Georg Kallidis <ge...@cedis.fu-berlin.de>.
Hi Thomas,
I agree with how you decided to do it defining the functional interfaces
one layer below assembler (actions, page, scheduledjobs, screen..) keeping
the different method names and the changes minimal.
We may continue think about checked exceptions, that is, if we really want
retain the checked exceptions - but I am fine for now.
Nonetheless removing the checked exceptions might be worth to be
considered in a second move (release, later) ..
Best regards, Georg
P.S. What about valve? We may make this a functional interface as well and
use e.g. spliterator in TurbinePipeline. But same here, it may be worth
the effort only (getting cleaner code, be close to java functional
lambdas), if removing/better handling the checked exceptions..
Von: Thomas Vandahl <tv...@apache.org>
An: Turbine Developers List <de...@turbine.apache.org>
Datum: 04.03.2019 19:21
Betreff: Re: Change modules to interfaces
Hi folks,
On 04.03.19 09:52, Georg Kallidis wrote:
> Making use of the functional interface just straight as in your code
might
> be the best choice keeping some valuable name conventions (java Consumer
> interface definition might be similar).
Thanks for your input. I tried to implement Assembler as an extension to
Consumer<PipelineData> but got bitten by the limitation that the whole
functional stuff cannot handle checked Exceptions.
I'm open to suggestions how we could get around this. I'd really like to
simplify the whole mess of Loaders, Factories, Brokers and such.
Bye, Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
For additional commands, e-mail: dev-help@turbine.apache.org
Re: Change modules to interfaces
Posted by Thomas Vandahl <tv...@apache.org>.
Hi folks,
On 04.03.19 09:52, Georg Kallidis wrote:
> Making use of the functional interface just straight as in your code might
> be the best choice keeping some valuable name conventions (java Consumer
> interface definition might be similar).
Thanks for your input. I tried to implement Assembler as an extension to
Consumer<PipelineData> but got bitten by the limitation that the whole
functional stuff cannot handle checked Exceptions.
I'm open to suggestions how we could get around this. I'd really like to
simplify the whole mess of Loaders, Factories, Brokers and such.
Bye, Thomas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
For additional commands, e-mail: dev-help@turbine.apache.org
Re: Re: Change modules to interfaces
Posted by Georg Kallidis <ge...@cedis.fu-berlin.de>.
Hi Thomas,
still using some Jetspeed-1 code which relies on extending ActionEvent,
but things will become more transparent (and more clean).
Making use of the functional interface just straight as in your code might
be the best choice keeping some valuable name conventions (java Consumer
interface definition might be similar).
But go ahead, we'll test ;-) !
Best regards, Georg
Von: "Jeffery Painter" <je...@jivecast.com>
An: "Turbine Developers List" <de...@turbine.apache.org>
Datum: 03.03.2019 21:29
Betreff: Re: Change modules to interfaces
Hi Thomas,
I have never done anything more than extend the VelocitySecureAction or
the o.a.t.m.Action class. I presume that adapting to this as an interface
instead of base class would not be too much work to update.
I would say go ahead, and I am happy to give it a try
-
Jeff
> Hi folks,
>
> I finally found the time to try something I planned to do for Turbine
> 4.0 already. I changed all modules (Action, Page, Screen,...) to be
> (functional) interfaces instead of base classes. This works fine but
> results in some methods to be public that were protected before.
>
> The advantage is that the whole module and loader code is much cleaner
> and simpler now and less spread over the different classes.
>
> Before I commit this, I wanted to ask if any of your code heavily relies
> on the old behavior?
>
> Bye, Thomas
>
> Example for Action:
>
> --8<--
> @FunctionalInterface
> public interface Action extends Assembler
> {
> /** Prefix for action related classes and templates */
> String PREFIX = "actions";
>
> /** Property for the size of the module cache if caching is on */
> String CACHE_SIZE_KEY = "action.cache.size";
>
> /** The default size for the action cache */
> int CACHE_SIZE_DEFAULT = 20;
>
> /** Represents Action Objects */
> String NAME = "action";
>
> /**
> * A subclass must implement this method to perform itself. The
> * Action can also set the screen that is associated with {@link
> PipelineData}.
> *
> * @param pipelineData Turbine information.
> * @throws Exception a generic exception.
> */
> void doPerform(PipelineData pipelineData) throws Exception;
>
> /**
> * Subclasses can override this method to add additional
> * functionality.
> *
> * @param pipelineData Turbine information.
> * @throws Exception a generic exception.
> */
> default void perform(PipelineData pipelineData) throws Exception
> {
> doPerform(pipelineData);
> }
> }
> --8<--
>
> Example for ActionLoader:
>
> --8<--
> public class ActionLoader
> extends GenericLoader<Action>
> {
> /** The single instance of this class. */
> private static ActionLoader instance = new ActionLoader();
>
> /**
> * These ctor's are private to force clients to use getInstance()
> * to access this class.
> */
> private ActionLoader()
> {
> super(Action.class,
> () -> Turbine.getConfiguration().getInt(Action.CACHE_SIZE_KEY,
> Action.CACHE_SIZE_DEFAULT));
> }
>
> /**
> * Attempts to load and execute the external action.
> *
> * @param pipelineData Turbine information.
> * @param name Name of object that will execute the action.
> * @throws Exception a generic exception.
> */
> @Override
> public void exec(PipelineData pipelineData, String name)
> throws Exception
> {
> getAssembler(name).perform(pipelineData);
> }
>
> /**
> * The method through which this class is accessed.
> *
> * @return The single instance of this class.
> */
> public static ActionLoader getInstance()
> {
> return instance;
> }
> }
> --8<--
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
> For additional commands, e-mail: dev-help@turbine.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
For additional commands, e-mail: dev-help@turbine.apache.org
Re: Change modules to interfaces
Posted by Jeffery Painter <je...@jivecast.com>.
Hi Thomas,
I have never done anything more than extend the VelocitySecureAction or
the o.a.t.m.Action class. I presume that adapting to this as an interface
instead of base class would not be too much work to update.
I would say go ahead, and I am happy to give it a try
-
Jeff
> Hi folks,
>
> I finally found the time to try something I planned to do for Turbine
> 4.0 already. I changed all modules (Action, Page, Screen,...) to be
> (functional) interfaces instead of base classes. This works fine but
> results in some methods to be public that were protected before.
>
> The advantage is that the whole module and loader code is much cleaner
> and simpler now and less spread over the different classes.
>
> Before I commit this, I wanted to ask if any of your code heavily relies
> on the old behavior?
>
> Bye, Thomas
>
> Example for Action:
>
> --8<--
> @FunctionalInterface
> public interface Action extends Assembler
> {
> /** Prefix for action related classes and templates */
> String PREFIX = "actions";
>
> /** Property for the size of the module cache if caching is on */
> String CACHE_SIZE_KEY = "action.cache.size";
>
> /** The default size for the action cache */
> int CACHE_SIZE_DEFAULT = 20;
>
> /** Represents Action Objects */
> String NAME = "action";
>
> /**
> * A subclass must implement this method to perform itself. The
> * Action can also set the screen that is associated with {@link
> PipelineData}.
> *
> * @param pipelineData Turbine information.
> * @throws Exception a generic exception.
> */
> void doPerform(PipelineData pipelineData) throws Exception;
>
> /**
> * Subclasses can override this method to add additional
> * functionality.
> *
> * @param pipelineData Turbine information.
> * @throws Exception a generic exception.
> */
> default void perform(PipelineData pipelineData) throws Exception
> {
> doPerform(pipelineData);
> }
> }
> --8<--
>
> Example for ActionLoader:
>
> --8<--
> public class ActionLoader
> extends GenericLoader<Action>
> {
> /** The single instance of this class. */
> private static ActionLoader instance = new ActionLoader();
>
> /**
> * These ctor's are private to force clients to use getInstance()
> * to access this class.
> */
> private ActionLoader()
> {
> super(Action.class,
> () -> Turbine.getConfiguration().getInt(Action.CACHE_SIZE_KEY,
> Action.CACHE_SIZE_DEFAULT));
> }
>
> /**
> * Attempts to load and execute the external action.
> *
> * @param pipelineData Turbine information.
> * @param name Name of object that will execute the action.
> * @throws Exception a generic exception.
> */
> @Override
> public void exec(PipelineData pipelineData, String name)
> throws Exception
> {
> getAssembler(name).perform(pipelineData);
> }
>
> /**
> * The method through which this class is accessed.
> *
> * @return The single instance of this class.
> */
> public static ActionLoader getInstance()
> {
> return instance;
> }
> }
> --8<--
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
> For additional commands, e-mail: dev-help@turbine.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@turbine.apache.org
For additional commands, e-mail: dev-help@turbine.apache.org