Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Refactor store-update into store-sync
Browse files Browse the repository at this point in the history
* 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
berezovskyi committed Mar 11, 2018
1 parent bbb5370 commit e1a70a9
Show file tree
Hide file tree
Showing 31 changed files with 894 additions and 18 deletions.
28 changes: 28 additions & 0 deletions LICENSE.EDL
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.
14 changes: 12 additions & 2 deletions src/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>store-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Lyo Store Parent</name>
<name>Lyo Store :: Parent</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -19,7 +19,7 @@

<modules>
<module>store-core</module>
<module>store-update</module>
<module>store-sync</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -55,6 +55,12 @@
<artifactId>xml-apis</artifactId>
<version>1.3.04</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<!-- Test -->
<dependency>
Expand Down Expand Up @@ -103,5 +109,9 @@
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://www.eclipse.org/org/documents/edl-v10.html</url>
</license>
</licenses>
</project>
10 changes: 5 additions & 5 deletions src/store-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
hs_err_pid*

# Eclipse
.project
.classpath
.metadata
/.project
/.classpath
/.metadata
*.tmp
*.bak
*.swp
Expand Down Expand Up @@ -63,8 +63,8 @@ local.properties
# MAVEN
#########################

**/overlays/
**/target/
/overlays/
/target/
pom.xml.tag
pom.xml.next
release.properties
Expand Down
6 changes: 5 additions & 1 deletion src/store-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>

<artifactId>store-core</artifactId>
<version>2.4.0-SNAPSHOT</version>
<name>Lyo Store :: Core</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -243,5 +243,9 @@
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://www.eclipse.org/org/documents/edl-v10.html</url>
</license>
</licenses>
</project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 18 additions & 10 deletions src/store-update/pom.xml → src/store-sync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,30 @@
<parent>
<groupId>org.eclipse.lyo.store</groupId>
<artifactId>store-parent</artifactId>
<version>2.3.0-SNAPSHOT</version>
<version>2.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>store-update</artifactId>
<artifactId>store-sync</artifactId>
<name>Lyo Store :: Sync</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<oslc4j-core.version>2.3.0-SNAPSHOT</oslc4j-core.version>
<version.lyo>2.4.0-SNAPSHOT</version.lyo>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.lyo.store</groupId>
<artifactId>store-core</artifactId>
<version>${oslc4j-core.version}</version>
<version>${version.lyo}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -39,7 +45,7 @@
<dependency>
<groupId>org.eclipse.lyo.trs</groupId>
<artifactId>trs-provider</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>${version.lyo}</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
Expand Down Expand Up @@ -86,7 +92,7 @@
</organizationName>
<inceptionYear>2016</inceptionYear>
<descriptionTemplate>
${basedir}/src/license//eplv1/description.txt.ftl
${basedir}/src/license/eplv1/description.txt.ftl
</descriptionTemplate>
<addJavaLicenseAfterPackage>true
</addJavaLicenseAfterPackage>
Expand Down Expand Up @@ -197,20 +203,22 @@
<name>Eclipse Public License 1.0</name>
<url>https://www.eclipse.org/legal/epl-v10.html</url>
</license>
<license>
<name>Eclipse Distribution License 1.0</name>
<url>https://www.eclipse.org/org/documents/edl-v10.html</url>
</license>
</licenses>

<repositories>
<repository>
<id>lyo-releases</id>
<name>lyo-releases repository</name>
<url>https://repo.eclipse.org/content/repositories/lyo-releases/
</url>
<url>https://repo.eclipse.org/content/repositories/lyo-releases/</url>
</repository>
<repository>
<id>lyo-snapshots</id>
<name>lyo-snapshots repository</name>
<url>https://repo.eclipse.org/content/repositories/lyo-snapshots/
</url>
<url>https://repo.eclipse.org/content/repositories/lyo-snapshots/</url>
</repository>
</repositories>
</project>
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);
}
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();
}
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);
}
}
Loading

0 comments on commit e1a70a9

Please sign in to comment.