This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor store-update into store-sync
* Add both EPL and EDL licenses * Rename artefacts in POMs * Rebase on top of the Jena 3.6.0 move Signed-off-by: Andrew Berezovskyi <[email protected]>
- Loading branch information
1 parent
bbb5370
commit e1a70a9
Showing
31 changed files
with
894 additions
and
18 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,28 @@ | ||
Eclipse Distribution License - v 1.0 | ||
|
||
Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. | ||
|
||
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 the Eclipse Foundation, Inc. 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 OWNER 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. |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
src/store-sync/src/main/java/org/eclipse/lyo/store/sync/Handler.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,16 @@ | ||
package org.eclipse.lyo.store.sync; | ||
|
||
import java.util.Collection; | ||
import org.eclipse.lyo.store.Store; | ||
import org.eclipse.lyo.store.sync.change.Change; | ||
|
||
/** | ||
* Handler is . | ||
* | ||
* @author Andrew Berezovskyi ([email protected]) | ||
* @version $version-stub$ | ||
* @since 0.0.0 | ||
*/ | ||
public interface Handler<M> { | ||
Collection<Change<M>> handle(Store store, Collection<Change<M>> changes); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/store-sync/src/main/java/org/eclipse/lyo/store/sync/ServiceProviderMessage.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,14 @@ | ||
package org.eclipse.lyo.store.sync; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Created on 06.03.17 | ||
* | ||
* @author Andrew Berezovskyi ([email protected]) | ||
* @version $version-stub$ | ||
* @since 0.0.1 | ||
*/ | ||
public interface ServiceProviderMessage { | ||
URI getServiceProviderUri(); | ||
} |
102 changes: 102 additions & 0 deletions
102
src/store-sync/src/main/java/org/eclipse/lyo/store/sync/StoreUpdateManager.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,102 @@ | ||
package org.eclipse.lyo.store.sync; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import org.eclipse.lyo.store.Store; | ||
import org.eclipse.lyo.store.sync.change.Change; | ||
import org.eclipse.lyo.store.sync.change.ChangeProvider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Schedules {@link StoreUpdateRunnable} via internal | ||
* {@link ScheduledExecutorService} with a predefined delay or on-demand. | ||
* Operates on a generic message that is passed to handlers. | ||
* | ||
* @author Andrew Berezovskyi ([email protected]) | ||
* @version $version-stub$ | ||
* @since 0.0.0 | ||
*/ | ||
public class StoreUpdateManager<M> { | ||
private final static Logger LOGGER = LoggerFactory.getLogger(StoreUpdateManager.class); | ||
private static final int NODELAY = 0; | ||
private static final int SINGLE_THREAD_POOL = 1; | ||
private final ScheduledExecutorService executor; | ||
private final ChangeProvider<M> changeProvider; | ||
private final Store store; | ||
private final List<Handler<M>> handlers = new ArrayList<>(); | ||
|
||
/** | ||
* Schedules {@link StoreUpdateRunnable} via internal | ||
* {@link ScheduledExecutorService} with a predefined delay or on-demand. | ||
* | ||
* @param store | ||
* Instance of an initialised Store | ||
* @param changeProvider | ||
* Provider of the changes in the underlying tool. | ||
*/ | ||
public StoreUpdateManager(final Store store, final ChangeProvider<M> changeProvider) { | ||
executor = Executors.newScheduledThreadPool(StoreUpdateManager.SINGLE_THREAD_POOL); | ||
this.store = store; | ||
this.changeProvider = changeProvider; | ||
} | ||
|
||
/** | ||
* Polling update on a given {@link ChangeProvider} followed by a notification | ||
* to all previously registered {@link Handler} objects. | ||
* | ||
* @param lastUpdate | ||
* Time of last store update, changes before this moment might be | ||
* dropped. | ||
* @param delaySeconds | ||
* Seconds between polling checks. | ||
*/ | ||
public void poll(final ZonedDateTime lastUpdate, final int delaySeconds) { | ||
final StoreUpdateRunnable<M> updateRunnable = buildRunnable(store, changeProvider, lastUpdate, null, handlers); | ||
executor.scheduleWithFixedDelay(updateRunnable, StoreUpdateManager.NODELAY, delaySeconds, TimeUnit.SECONDS); | ||
|
||
StoreUpdateManager.LOGGER.trace("Poll request has been enqueued"); | ||
} | ||
|
||
/** | ||
* Submit a single update request. Typically done from the HTTP handler. | ||
* | ||
* @param lastUpdate | ||
* @param message | ||
* Specific details for the {@link ChangeProvider} | ||
* @return {@link Future} that allows to block until the runnable is finished | ||
* executing (strongly discouraged). | ||
*/ | ||
public Future<?> submit(final ZonedDateTime lastUpdate, final M message) { | ||
final StoreUpdateRunnable<M> updateRunnable = buildRunnable(store, changeProvider, lastUpdate, message, | ||
handlers); | ||
return executor.submit(updateRunnable); | ||
} | ||
|
||
/** | ||
* Add a {@link Handler} that will process the collection of {@link Change} | ||
* generated by the {@link ChangeProvider}. Handler is not guaranteed to be | ||
* called if added after the update has been scheduled. | ||
* | ||
* @param handler | ||
* Handler that should be called whenever {@link ChangeProvider} | ||
* returns any changes. | ||
*/ | ||
public void addHandler(final Handler<M> handler) { | ||
handlers.add(handler); | ||
} | ||
|
||
/** | ||
* Method can be overridden in case a more sophisticated Runnable has to be | ||
* constructed. | ||
*/ | ||
protected StoreUpdateRunnable<M> buildRunnable(final Store store, final ChangeProvider<M> changeProvider, | ||
final ZonedDateTime lastUpdate, final M message, final List<Handler<M>> handlers) { | ||
return new StoreUpdateRunnable<>(store, changeProvider, lastUpdate, message, handlers); | ||
} | ||
} |
Oops, something went wrong.