-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing NIO server. Added: - Netty server instead of simple IO-based. Changed: - The way of serialization/deserialization of EPMD messages.
- Loading branch information
Showing
56 changed files
with
866 additions
and
1,138 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
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
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
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
80 changes: 80 additions & 0 deletions
80
core/src/main/java/io/appulse/epmd/java/core/mapper/deserializer/RequestDeserializer.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,80 @@ | ||
/* | ||
* 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.epmd.java.core.mapper.deserializer; | ||
|
||
import io.appulse.epmd.java.core.mapper.deserializer.exception.DeserializationException; | ||
import io.appulse.epmd.java.core.mapper.deserializer.exception.InvalidReceivedMessageLengthException; | ||
import io.appulse.epmd.java.core.mapper.deserializer.exception.InvalidReceivedMessageTagException; | ||
import io.appulse.epmd.java.core.model.Tag; | ||
import io.appulse.epmd.java.core.model.request.Request; | ||
import io.appulse.utils.Bytes; | ||
|
||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
|
||
/** | ||
* | ||
* @author Artem Labazin | ||
* @since 0.4.0 | ||
*/ | ||
@Slf4j | ||
class RequestDeserializer implements Deserializer { | ||
|
||
@Override | ||
public <T> T deserialize (@NonNull Bytes bytes, @NonNull Class<T> type) throws DeserializationException { | ||
val length = bytes.getShort(); | ||
if (length != bytes.remaining()) { | ||
val message = String.format("Expected length is %d - %d bytes, but actual length is %d bytes.", | ||
2, length, bytes.remaining()); | ||
log.error(message); | ||
throw new InvalidReceivedMessageLengthException(message); | ||
} | ||
|
||
T result; | ||
try { | ||
result = type.newInstance(); | ||
} catch (IllegalAccessException | InstantiationException ex) { | ||
log.error("Deserialized type instantiation error", ex); | ||
throw new DeserializationException(ex); | ||
} | ||
|
||
if (!(result instanceof Request)) { | ||
val message = String.format("Deserializing type '%s' is not an instance of '%s'", | ||
type.getSimpleName(), Request.class.getSimpleName()); | ||
log.error(message); | ||
throw new DeserializationException(message); | ||
} | ||
val request = (Request) result; | ||
|
||
val tag = Tag.of(bytes.getByte()); | ||
if (tag != request.getTag()) { | ||
val message = String.format("Expected tag is: %s, but actual tag is: %s", | ||
request.getTag(), tag); | ||
log.error(message); | ||
throw new InvalidReceivedMessageTagException(message); | ||
} | ||
|
||
request.read(bytes); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable (@NonNull Class<?> type) { | ||
return Request.class.isAssignableFrom(type); | ||
} | ||
} |
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
Oops, something went wrong.