Skip to content

Commit

Permalink
Initial Github Release.
Browse files Browse the repository at this point in the history
Includes an incomplete TChannel implementation in Java. So far, the
basic `Message` types have been defined along with most of their
Encode/Decode logic ( Codecs ). These `Message`s represent message
primitives that the TChannel protocol speaks.

A basic `MessageMultiplexer` is also nearly complete, and is responsible
for re-constructing large Arg{1,2,3} payloads, or streaming payloads
that are necessarily chunked across multiple message containers.

The API design ( client / server APIs ) is still very much a WIP, but
the basic ideas are outlined in the README.md, and will be incorporated
into the Server and Client examples as more of the API is completed. The
Server and Client examples will also serve as a reference implementation
for those wishing to use tchannel4j in their projects.
  • Loading branch information
Will Salisbury committed Jul 27, 2015
0 parents commit 0dcc1b5
Show file tree
Hide file tree
Showing 63 changed files with 3,735 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.idea/
tchannel-core/target/
tchannel-example/target/
*.iml
2 changes: 2 additions & 0 deletions .travis.yml
@@ -0,0 +1,2 @@
sudo: false
language: java
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2015 Uber Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
@@ -0,0 +1,44 @@
# TChannel for the JVM

A Java implementation of the [TChannel](https://github.com/uber/tchannel) protocol.

## Stability: *Experimental*

## Completed
- Frame codecs
- Message codecs
- Checksumming
- Message Multiplexing a.k.a. fragment aggregation

## In Progress
- Tracing

## TODO
- Final API design and implementation
- Message Canceling
- Message Claiming
- Handling Errors properly
- Performance

## *Proposed* Example Usage

```java
TChannel server = new TChannel('server');
server.register('noop', new RawRequestHandler() {
@Override
public void onRequest(Stream s, Request req) {
System.out.println(req);
}
});
ChannelFuture f = server.listen('127.0.0.1:8888');
f.addListener(ChannelFutureListener.CLOSE_ON_FAILURE)

TChannel client = new TChannel('client');
ChannelFuture response = client.request('127.0.0.1:8888', 'noop', new RawRequest('func1', 'arg1', 'arg2'));
response.addListener(new ChannelFutureListener {
@Override
public void operationComplete(ChannelFuture f) {
System.out.println(f.isSuccess());
}
});
```
31 changes: 31 additions & 0 deletions pom.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>com.uber.tchannel</groupId>
<artifactId>tchannel</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>tchannel-core</module>
<module>tchannel-example</module>
</modules>

<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>5.0.0.Alpha2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
18 changes: 18 additions & 0 deletions tchannel-core/pom.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>tchannel</artifactId>
<groupId>com.uber.tchannel</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>tchannel-core</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
25 changes: 25 additions & 0 deletions tchannel-core/src/main/java/com/uber/tchannel/api/Request.java
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2015 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.tchannel.api;

public class Request {
}
25 changes: 25 additions & 0 deletions tchannel-core/src/main/java/com/uber/tchannel/api/Response.java
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2015 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.tchannel.api;

public class Response {
}
44 changes: 44 additions & 0 deletions tchannel-core/src/main/java/com/uber/tchannel/api/TChannel.java
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2015 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.tchannel.api;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class TChannel {

public final String channelName;

public TChannel(String channelName) {
this.channelName = channelName;
}

public FutureTask<Response> request(final Request request) {
return new FutureTask<Response>(new Callable<Response>() {
public Response call() throws Exception {
System.out.println(request);
return new Response();
}
});
}

}
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2015 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.tchannel.checksum;

import java.util.Optional;

public enum ChecksumType {
NoChecksum((byte) 0x00),
Adler32((byte) 0x1),
FarmhashFingerPrint32((byte) 0x02),
CRC32C((byte) 0x03);

private final byte type;

ChecksumType(byte type) {
this.type = type;
}

public static Optional<ChecksumType> fromByte(byte value) {
switch (value) {
case (byte) 0x00:
return Optional.of(NoChecksum);
case (byte) 0x01:
return Optional.of(Adler32);
case (byte) 0x02:
return Optional.of(FarmhashFingerPrint32);
case (byte) 0x03:
return Optional.of(CRC32C);
default:
return Optional.empty();
}
}

public byte byteValue() {
return this.type;
}


}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2015 Uber Technologies, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.uber.tchannel.checksum;

import com.uber.tchannel.messages.AbstractCallMessage;

import java.util.List;
import java.util.zip.Adler32;

public class Checksums {
public static boolean verifyChecksum(AbstractCallMessage msg) {
return (calculateChecksum(msg) == msg.getChecksum());
}


public static boolean verifyChecksum(List<AbstractCallMessage> messageList) {

long checksum = 0L;

for (AbstractCallMessage msg : messageList) {
checksum = calculateChecksum(msg, checksum);
if (checksum != msg.getChecksum()) {
return false;
}
}

return true;
}

public static boolean verifyExistingChecksum(AbstractCallMessage msg, long checksum) {
return (msg.getChecksum() == checksum);
}

public static long calculateChecksum(AbstractCallMessage msg) {
return calculateChecksum(msg, 0L);
}

public static long calculateChecksum(AbstractCallMessage msg, long digestSeed) {

long checksum;

switch (ChecksumType.fromByte(msg.getChecksumType()).get()) {

case Adler32:
Adler32 f = new Adler32();
f.update((int) digestSeed);
f.update(msg.getArg1().nioBuffer());
f.update(msg.getArg2().nioBuffer());
f.update(msg.getArg2().nioBuffer());
checksum = f.getValue();
break;
case FarmhashFingerPrint32:
case NoChecksum:
case CRC32C:
default:
checksum = 0;
break;
}

return checksum;
}


}

0 comments on commit 0dcc1b5

Please sign in to comment.