Skip to content

Tick tock fix #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add tests.
- Rething caches in terms and modules.
- Add lazy deserialization for terms.
- Add `UDP`/`SCTP` protocols support.
- Rethink handshake implementation design.
- Add handshake error handling (exceptions? error logs?).
- Turn on checkstyle JavaDocs module.
- Add updates to the protocol, like new `ControlMessage`.

## [1.3.1](https://github.com/appulse-projects/encon-java/releases/tag/1.3.1) - 2018-06-28

Fix short node name host detection.

## [1.3.0](https://github.com/appulse-projects/encon-java/releases/tag/1.3.0) - 2018-06-28

Expand Down
2 changes: 1 addition & 1 deletion encon-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-parent</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>

<artifactId>encon-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public class NodeDescriptor implements Serializable {

private static final InetAddress LOOPBACK;

private static final String HOST_NAME;
private static final String LONG_HOST_NAME;

private static final String SHORT_HOST_NAME;

static {
try {
Expand All @@ -74,7 +76,11 @@ public class NodeDescriptor implements Serializable {
throw new RuntimeException(ex);
}
LOOPBACK = InetAddress.getLoopbackAddress();
HOST_NAME = LOCALHOST.getHostName();
LONG_HOST_NAME = LOCALHOST.getHostName();
val dotIndex = LONG_HOST_NAME.indexOf('.');
SHORT_HOST_NAME = dotIndex > 0
? LONG_HOST_NAME.substring(dotIndex)
: LONG_HOST_NAME;
NODE_DESCRIPTOR_CACHE = new ConcurrentHashMap<>();
}

Expand Down Expand Up @@ -216,16 +222,14 @@ private static NodeDescriptor parse (@NonNull String node, boolean isShortName)
hostName);
throw new IllegalArgumentException(message);
}
address = InetAddress.getByName(hostName);
address = isShortName
? LOOPBACK
: InetAddress.getByName(hostName);
} else if (isShortName) {
val dotIndex = HOST_NAME.indexOf('.');
hostName = dotIndex > 0
? HOST_NAME.substring(dotIndex)
: HOST_NAME;

hostName = SHORT_HOST_NAME;
address = LOOPBACK;
} else {
hostName = HOST_NAME;
hostName = LONG_HOST_NAME;
address = LOCALHOST;
}

Expand Down
4 changes: 2 additions & 2 deletions encon-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ First of all, add config's dependency:
<dependency>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-config</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</dependency>
...
</dependencies>
Expand All @@ -23,7 +23,7 @@ First of all, add config's dependency:
**Gradle**:

```groovy
compile 'io.appulse.encon.java:encon-config:1.3.0'
compile 'io.appulse.encon.java:encon-config:1.3.1'
```

### File based configuration
Expand Down
2 changes: 1 addition & 1 deletion encon-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-parent</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>

<artifactId>encon-config</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions encon-databind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ First of all, add databind's dependency:
<dependency>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-databind</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</dependency>
...
</dependencies>
Expand All @@ -23,7 +23,7 @@ First of all, add databind's dependency:
**Gradle**:

```groovy
compile 'io.appulse.encon.java:encon-databind:1.3.0'
compile 'io.appulse.encon.java:encon-databind:1.3.1'
```

Let's imagine, you have POJO like this:
Expand Down
2 changes: 1 addition & 1 deletion encon-databind/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-parent</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>

<artifactId>encon-databind</artifactId>
Expand Down
113 changes: 113 additions & 0 deletions encon-spring/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-parent</artifactId>
<version>1.1.0</version>
</parent>

<artifactId>encon-spring</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>encon</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appulse.encon.spring;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Indicates that an annotated class is a "Controller" (e.g. a web controller).
*
* <p>This annotation serves as a specialization of {@link Component @Component},
* allowing for implementation classes to be autodetected through classpath scanning.
* It is typically used in combination with annotated handler methods based on the
* {@link org.springframework.web.bind.annotation.RequestMapping} annotation.
*
* @since 1.2.0
* @author Artem Labazin
*
* @see Component
* @see org.springframework.web.bind.annotation.RequestMapping
* @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
*/
@Component
@Documented
@Target(FIELD)
@Retention(RUNTIME)
public @interface ErlangController {

/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any
*/
String value() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@


@ErlangController
public class MyController {

/**
* Default listener parameters with:
* - default mailbox (primary one)
* - default node (primary bean)
* - no wrapper
*/
@MailboxListener
public void doSome1 (ErlangTerm term) {
// ...
}

/**
* The same as previous, but with custom user POJO
*/
@MailboxListener
public void doSome2 (MyPojo pojo) {
// ...
}

@MailboxListener(
node = "my-node-name", // not default node
mailbox = "the-first-one", // specify mailbox, not default one
wrapper = TUPLE // request wrapper tupe, all args below wraped in this
)
public void doSome3 (@AsEralngAtom String myAtom, Integer age) {
// ...
}
}

@ErlangController
public class MyController {

@MailboxListener
public void doSome1 (@AsErlangAtom String atom) {
System.out.println("hello!");


builder
.case(service).myHandler1(42, anyInt(), anyString())
.case(service).myHandler2(3, anyInt(), anyString())
.case(service).myHandler3(anyInt(), anyInt(), anyString());

builder
.case()
.tuple(int(3), any(), any())
.handler(...)
.case()
.tuple(any(), any(), any())
.handler(...)
.case()
.tuple(int(42), any(), any())
.handler(...);

}

@MailboxListener
public void doSome2 (@Expected("42") Integer age) {
System.out.println("world!");
}

@MailboxListener
public void doSome3 (@Expected("3") Integer age) {
System.out.println("popa");
}
}
2 changes: 1 addition & 1 deletion encon-terms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ limitations under the License.
<parent>
<groupId>io.appulse.encon</groupId>
<artifactId>encon-parent</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
</parent>

<artifactId>encon-terms</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public abstract class ErlangTerm implements IntegerTerm,
*/
@SuppressWarnings("unchecked")
public static <T extends ErlangTerm> T newInstance (@NonNull ByteBuf buffer) {
val type = TermType.of(buffer.readByte());
val typeByte = buffer.readByte();
val type = TermType.of(typeByte);

switch (type) {
case SMALL_INTEGER:
Expand Down Expand Up @@ -134,7 +135,8 @@ public static <T extends ErlangTerm> T newInstance (@NonNull ByteBuf buffer) {
case SMALL_ATOM:
return (T) new ErlangAtom(type, buffer);
default:
throw new ErlangTermDecodeException("Unknown term type " + type);
val message = String.format("Unknown term type %s (%d)", type.name(), typeByte);
throw new ErlangTermDecodeException(message);
}
}

Expand Down
Loading