Skip to content

Commit

Permalink
Update the "shared" module with checkstyle checks.
Browse files Browse the repository at this point in the history
Remove extra callback class that composed two existing callbacks.
  • Loading branch information
prd-fox committed Apr 12, 2019
1 parent d38f5d5 commit 1493b8d
Show file tree
Hide file tree
Showing 31 changed files with 180 additions and 233 deletions.
7 changes: 7 additions & 0 deletions checkstyle.xml
Expand Up @@ -128,6 +128,13 @@
<!--<property name="tokens" value="LOR, LAND"/>--> <!-- TODO: uncomment -->
<property name="tokens" value="EQUAL, NOT_EQUAL"/>
</module>

<!-- <module name="EmptyLineSeparator">-->
<!-- <property name="allowNoEmptyLineBetweenFields" value="false"/>-->
<!-- <property name="allowMultipleEmptyLines" value="false" />-->
<!-- <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>-->
<!-- </module>-->

</module>

</module>
@@ -1,5 +1,8 @@
package com.quorum.tessera.data.migration;

import com.quorum.tessera.io.IOCallback;
import com.quorum.tessera.nio.unix.UriCallback;

import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -18,9 +21,11 @@ public class JdbcDataExporter implements DataExporter {
private final List<String> createTables;

public JdbcDataExporter(String jdbcUrl, String insertRow, URL ddl) {
final Path uri = UriCallback.execute(() -> Paths.get(ddl.toURI()));

this.jdbcUrl = jdbcUrl;
this.insertRow = insertRow;
this.createTables = UriCallback.execute(() -> Files.readAllLines(Paths.get(ddl.toURI())));
this.createTables = IOCallback.execute(() -> Files.readAllLines(uri));
}

@Override
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -7,10 +7,12 @@
public interface ServiceLoaderUtil {

static <T> Optional<T> load(Class<T> type) {
Iterator<T> it = ServiceLoader.load(type).iterator();
final Iterator<T> it = ServiceLoader.load(type).iterator();

if (it.hasNext()) {
return Optional.of(it.next());
}

return Optional.empty();
}

Expand Down
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import java.util.stream.Stream;

/**
* <p>
* Delegates calls to nio Files functions unchecking IOExceptions
Expand All @@ -28,7 +29,6 @@ default boolean deleteIfExists(Path path) {
return IOCallback.execute(() -> Files.deleteIfExists(path));
}


default Path createFile(Path path, FileAttribute... attributes) {

return IOCallback.execute(() -> Files.createFile(path, attributes));
Expand Down
Expand Up @@ -28,6 +28,6 @@ public void write(int b) throws IOException {
});
}

};
}

}
6 changes: 3 additions & 3 deletions shared/src/main/java/com/quorum/tessera/io/SystemAdapter.java
@@ -1,12 +1,12 @@
package com.quorum.tessera.io;

import com.quorum.tessera.ServiceLoaderUtil;

import java.io.PrintStream;

public interface SystemAdapter {

SystemAdapter INSTANCE = ServiceLoaderUtil.load(SystemAdapter.class)
.orElse(new SystemAdapter() {

SystemAdapter INSTANCE = ServiceLoaderUtil.load(SystemAdapter.class).orElse(new SystemAdapter() {
});

default PrintStream out() {
Expand Down
11 changes: 4 additions & 7 deletions shared/src/main/java/com/quorum/tessera/jaxb/JaxbCallback.java
@@ -1,22 +1,19 @@

package com.quorum.tessera.jaxb;

import javax.xml.bind.DataBindingException;
import javax.xml.bind.JAXBException;

@FunctionalInterface
public interface JaxbCallback<T> {


T doExecute() throws JAXBException,DataBindingException;



T doExecute() throws JAXBException, DataBindingException;

static <T> T execute(JaxbCallback<T> callback) {
try {
return callback.doExecute();
} catch (JAXBException ex) {
throw new DataBindingException(ex);
}
}

}
Expand Up @@ -7,15 +7,7 @@
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.AccessMode;
import java.nio.file.CopyOption;
import java.nio.file.DirectoryStream;
import java.nio.file.FileStore;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.LinkOption;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
Expand All @@ -26,7 +18,6 @@

/**
* Implementation of FileSystemProvider that handles URIs with unix scheme
*
*/
public class UnixSocketFileSystemProvider extends FileSystemProvider {

Expand All @@ -45,10 +36,18 @@ public String getScheme() {
return "unix";
}

private static URI convert(URI uri) {
return UriCallback.execute(() -> {
return new URI("file",uri.getUserInfo(),uri.getHost(),uri.getPort(),uri.getPath(),uri.getQuery(),uri.getFragment());
});
private static URI convert(final URI uri) {
return UriCallback.execute(
() -> new URI(
"file",
uri.getUserInfo(),
uri.getHost(),
uri.getPort(),
uri.getPath(),
uri.getQuery(),
uri.getFragment()
)
);

}

Expand Down
Expand Up @@ -4,7 +4,6 @@
import java.io.UncheckedIOException;
import java.net.URISyntaxException;


public interface UriCallback<T> {

T doExecute() throws URISyntaxException;
Expand All @@ -16,4 +15,5 @@ static <T> T execute(UriCallback<T> callback) {
throw new UncheckedIOException(new IOException(ex));
}
}

}
@@ -1,7 +1,5 @@

package com.quorum.tessera.reflect;


public class ReflectException extends RuntimeException {

public ReflectException(Throwable cause) {
Expand Down
3 changes: 1 addition & 2 deletions shared/src/main/java/com/quorum/tessera/service/Service.java
Expand Up @@ -3,8 +3,7 @@
public interface Service {

enum Status {
STARTED,
STOPPED
STARTED, STOPPED
}

void start();
Expand Down
@@ -1,34 +1,36 @@
package com.quorum.tessera.service;

import com.quorum.tessera.service.Service.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServiceContainer implements Runnable {

private static final Logger LOGGER = LoggerFactory.getLogger(ServiceContainer.class);

private Service service;
private final Service service;

private ScheduledExecutorService executorService;
private final ScheduledExecutorService executorService;

private long initialDelay;
private final long initialDelay;

private long period;
private final long period;

public ServiceContainer(Service service) {
public ServiceContainer(final Service service) {
this(service, Executors.newScheduledThreadPool(1), 1000L, 1000L);
}

public ServiceContainer(Service service,
ScheduledExecutorService executorService,
long initialDelay, long period) {
public ServiceContainer(final Service service,
final ScheduledExecutorService executorService,
final long initialDelay,
final long period) {
this.service = service;
this.executorService = executorService;
this.initialDelay = initialDelay;
Expand All @@ -48,22 +50,21 @@ public void stop() {

@Override
public void run() {
LOGGER.trace("Check status {}",service);
LOGGER.trace("Check status {}", service);
Status status = service.status();
LOGGER.trace("{} Status is {}",service,status);
LOGGER.trace("{} Status is {}", service, status);

if (status == Service.Status.STOPPED) {
LOGGER.warn("Service {} not stopped attempt to restart.",service);
LOGGER.warn("Service {} not stopped attempt to restart.", service);
try {
LOGGER.debug("Starting service {}",service);
LOGGER.debug("Starting service {}", service);
service.start();
LOGGER.debug("Started service {}",service);
LOGGER.debug("Started service {}", service);
} catch (Throwable ex) {
LOGGER.trace(null, ex);
LOGGER.warn("Exception thrown : {} While starting service {}",
Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(),service);
LOGGER.warn("Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service);
}
}
}

}
7 changes: 0 additions & 7 deletions shared/src/test/java/com/acme/Bogus.java

This file was deleted.

8 changes: 8 additions & 0 deletions shared/src/test/java/com/acme/DefaultTestService.java
@@ -0,0 +1,8 @@
package com.acme;

/**
* An implementation of {@link TestService} that can be loaded by the Java
* Service Loader
*/
public class DefaultTestService implements TestService {
}
8 changes: 8 additions & 0 deletions shared/src/test/java/com/acme/TestService.java
@@ -0,0 +1,8 @@
package com.acme;

/**
* An interface for testing the Service loader. See
* {@link com.quorum.tessera.ServiceLoaderUtilTest}.
*/
public interface TestService {
}
7 changes: 0 additions & 7 deletions shared/src/test/java/com/acme/VeryBogus.java

This file was deleted.

0 comments on commit 1493b8d

Please sign in to comment.