This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Use a factory to create VirtualSpout instances #71
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/com/salesforce/storm/spout/dynamic/DelegateSpoutFactory.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,71 @@ | ||
/** | ||
* Copyright (c) 2017, Salesforce.com, Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
* following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.salesforce.storm.spout.dynamic; | ||
|
||
import com.salesforce.storm.spout.dynamic.consumer.ConsumerState; | ||
import com.salesforce.storm.spout.dynamic.metrics.MetricsRecorder; | ||
|
||
/** | ||
* Factory for easily creating {@link DelegateSpout} instances. | ||
* | ||
* Handy in things like {@link com.salesforce.storm.spout.dynamic.handler.SpoutHandler} where we want to abstract away particulars, such | ||
* as the things passed down from {@link DynamicSpout} such as the {@link MetricsRecorder} as an example. | ||
*/ | ||
public interface DelegateSpoutFactory { | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
<T extends DelegateSpout> T create( | ||
final VirtualSpoutIdentifier identifier | ||
); | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @param startingState starting consumer state for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
<T extends DelegateSpout> T create( | ||
final VirtualSpoutIdentifier identifier, | ||
final ConsumerState startingState | ||
); | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @param startingState starting consumer state for this instance. | ||
* @param endingState ending consumer state for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
<T extends DelegateSpout> T create( | ||
final VirtualSpoutIdentifier identifier, | ||
final ConsumerState startingState, | ||
final ConsumerState endingState | ||
); | ||
} |
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
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
126 changes: 126 additions & 0 deletions
126
src/main/java/com/salesforce/storm/spout/dynamic/VirtualSpoutFactory.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,126 @@ | ||
/** | ||
* Copyright (c) 2017, Salesforce.com, Inc. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
* following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.salesforce.storm.spout.dynamic; | ||
|
||
import com.salesforce.storm.spout.dynamic.consumer.ConsumerState; | ||
import com.salesforce.storm.spout.dynamic.metrics.MetricsRecorder; | ||
import org.apache.storm.task.TopologyContext; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Factory for easily creating {@link DelegateSpout} instances. | ||
* | ||
* Handy in things like {@link com.salesforce.storm.spout.dynamic.handler.SpoutHandler} where we want to abstract away particulars, such | ||
* as the things passed down from {@link DynamicSpout} such as the {@link MetricsRecorder} as an example. | ||
*/ | ||
public class VirtualSpoutFactory implements DelegateSpoutFactory { | ||
|
||
/** | ||
* Spout configuration. | ||
*/ | ||
private final Map<String, Object> spoutConfig; | ||
/** | ||
* Topology context. | ||
*/ | ||
private final TopologyContext topologyContext; | ||
/** | ||
* Factory manager, for creating instances of classes driven by configuration. | ||
*/ | ||
private final FactoryManager factoryManager; | ||
/** | ||
* Metrics recorder, for capturing metrics. | ||
*/ | ||
private final MetricsRecorder metricsRecorder; | ||
|
||
/** | ||
* Factory for easily creating {@link DelegateSpout} instances. | ||
* | ||
* Handy in things like {@link com.salesforce.storm.spout.dynamic.handler.SpoutHandler} where we want to abstract away particulars, such | ||
* as the things passed down from {@link DynamicSpout} such as the {@link MetricsRecorder} as an example. | ||
*/ | ||
public VirtualSpoutFactory( | ||
final Map<String, Object> spoutConfig, | ||
final TopologyContext topologyContext, | ||
final FactoryManager factoryManager, | ||
final MetricsRecorder metricsRecorder | ||
) { | ||
this.spoutConfig = spoutConfig; | ||
this.topologyContext = topologyContext; | ||
this.factoryManager = factoryManager; | ||
this.metricsRecorder = metricsRecorder; | ||
} | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @param startingState starting consumer state for this instance. | ||
* @param endingState ending consumer state for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
@Override | ||
public VirtualSpout create( | ||
final VirtualSpoutIdentifier identifier, | ||
final ConsumerState startingState, | ||
final ConsumerState endingState | ||
) { | ||
return new VirtualSpout( | ||
identifier, | ||
this.spoutConfig, | ||
this.topologyContext, | ||
this.factoryManager, | ||
this.metricsRecorder, | ||
startingState, | ||
endingState | ||
); | ||
} | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @param startingState starting consumer state for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
@Override | ||
public VirtualSpout create( | ||
final VirtualSpoutIdentifier identifier, | ||
final ConsumerState startingState | ||
) { | ||
return create(identifier, startingState, null); | ||
} | ||
|
||
/** | ||
* Create a {@link DelegateSpout} instance. | ||
* @param identifier identifier to use for this instance. | ||
* @return instance of {@link DelegateSpout}. | ||
*/ | ||
@Override | ||
public VirtualSpout create( | ||
final VirtualSpoutIdentifier identifier | ||
) { | ||
return create(identifier, null, null); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test over this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, thanks for keeping me honest.