commit 9bcb96183d6242178b8441e7ad36861cf0475079 Author: Mihai Moldovanu Date: Sun Jun 9 13:59:37 2024 +0300 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..eeb554f --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7eec1db --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..3657318 --- /dev/null +++ b/build.gradle @@ -0,0 +1,31 @@ +plugins { + id 'java' + id "io.github.balookrd.scrooge-gradle-plugin" version "19.12.1" +} + + +group = 'org.example' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.scala-lang:scala-library:2.13.6' + implementation 'com.twitter:finagle-thriftmux_2.13:22.4.0' + implementation 'org.apache.thrift:libthrift:0.14.2' + + testImplementation platform('org.junit:junit-bom:5.10.0') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} + +compileScrooge { + thriftFiles = fileTree(dir: "src/main/thrift", include: "**/*.thrift") + dest = file("src/main/java") + opts = ["--finagle"] //default Java code, ["-l","scala"] for scala code +} diff --git a/generate_thrift.sh b/generate_thrift.sh new file mode 100644 index 0000000..79f2770 --- /dev/null +++ b/generate_thrift.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# old version +# thrift --gen java -o src/main/ src/main/thrift/hello.thrift +# mv src/main/gen-java/org/example/Hello.java src/main/java/org/example/Hello.java + +#new version ( scrooge ) +./gradlew compileScrooge diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6a02dcb --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed May 29 14:01:16 EEST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 +# +# https://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. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..8118786 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'javatest2' + diff --git a/src/main/java/org/example/FinagleThriftServer.java b/src/main/java/org/example/FinagleThriftServer.java new file mode 100644 index 0000000..123ccf2 --- /dev/null +++ b/src/main/java/org/example/FinagleThriftServer.java @@ -0,0 +1,16 @@ +package org.example; + +import com.twitter.finagle.ListeningServer; +import com.twitter.finagle.Thrift; +import com.twitter.util.Await; +import com.twitter.util.TimeoutException; + +public class FinagleThriftServer { + public static void main(String[] args) throws InterruptedException, TimeoutException { + HelloServiceImpl service = new HelloServiceImpl(); + ListeningServer server = Thrift.server() + .serveIface("localhost:8097", service); + System.out.println("Thrift server running on port 8097"); + Await.ready(server); + } +} \ No newline at end of file diff --git a/src/main/java/org/example/HelloService.java b/src/main/java/org/example/HelloService.java new file mode 100644 index 0000000..1a95605 --- /dev/null +++ b/src/main/java/org/example/HelloService.java @@ -0,0 +1,1921 @@ +/** + * Autogenerated by Thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + */ +package org.example; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; + +import org.apache.thrift.*; +import org.apache.thrift.async.*; +import org.apache.thrift.meta_data.*; +import org.apache.thrift.transport.*; +import org.apache.thrift.protocol.*; + +import com.twitter.scrooge.TReusableBuffer; +import com.twitter.scrooge.TReusableMemoryTransport; +import com.twitter.util.Future; +import com.twitter.util.Function; +import com.twitter.util.Function2; +import com.twitter.util.Try; +import com.twitter.util.Return; +import com.twitter.util.Throw; +import com.twitter.finagle.thrift.ClientDeserializeCtx; +import com.twitter.finagle.thrift.ServerToReqRep; +import com.twitter.finagle.thrift.ThriftClientRequest; + +public class HelloService { + public interface Iface { + public String sayHello(String name) throws TException; + public void blocking_call() throws TException; + } + + public interface AsyncIface { + public void sayHello(String name, AsyncMethodCallback resultHandler) throws TException; + public void blocking_call(AsyncMethodCallback resultHandler) throws TException; + } + + public interface ServiceIface { + public Future sayHello(String name); + public Future blocking_call(); + } + + public static class Client extends TServiceClient implements Iface { + public static class Factory implements TServiceClientFactory { + public Factory() {} + public Client getClient(TProtocol prot) { + return new Client(prot); + } + public Client getClient(TProtocol iprot, TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(TProtocol prot) + { + this(prot, prot); + } + + public Client(TProtocol iprot, TProtocol oprot) + { + super(iprot, oprot); + } + + public String sayHello(String name) throws TException + { + send_sayHello(name); + return recv_sayHello(); + } + + public void send_sayHello(String name) throws TException + { + oprot_.writeMessageBegin(new TMessage("sayHello", TMessageType.CALL, ++seqid_)); + sayHello_args __args__ = new sayHello_args(); + __args__.setName(name); + __args__.write(oprot_); + oprot_.writeMessageEnd(); + oprot_.getTransport().flush(); + } + + public String recv_sayHello() throws TException + { + TMessage msg = iprot_.readMessageBegin(); + if (msg.type == TMessageType.EXCEPTION) { + TApplicationException x = TApplicationException.readFrom(iprot_); + iprot_.readMessageEnd(); + throw x; + } + if (msg.seqid != seqid_) { + throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "sayHello failed: out of sequence response"); + } + sayHello_result result = new sayHello_result(); + result.read(iprot_); + iprot_.readMessageEnd(); + if (result.isSetSuccess()) { + return result.success; + } + throw new TApplicationException(TApplicationException.MISSING_RESULT, "sayHello failed: unknown result"); + } + public void blocking_call() throws TException + { + send_blocking_call(); + recv_blocking_call(); + } + + public void send_blocking_call() throws TException + { + oprot_.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, ++seqid_)); + blocking_call_args __args__ = new blocking_call_args(); + __args__.write(oprot_); + oprot_.writeMessageEnd(); + oprot_.getTransport().flush(); + } + + public void recv_blocking_call() throws TException + { + TMessage msg = iprot_.readMessageBegin(); + if (msg.type == TMessageType.EXCEPTION) { + TApplicationException x = TApplicationException.readFrom(iprot_); + iprot_.readMessageEnd(); + throw x; + } + if (msg.seqid != seqid_) { + throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, "blocking_call failed: out of sequence response"); + } + blocking_call_result result = new blocking_call_result(); + result.read(iprot_); + iprot_.readMessageEnd(); + return; + } + } + + public static class AsyncClient extends TAsyncClient implements AsyncIface { + public static class Factory implements TAsyncClientFactory { + private final TAsyncClientManager clientManager; + private final TProtocolFactory protocolFactory; + public Factory(TAsyncClientManager clientManager, TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + public AsyncClient getAsyncClient(TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + private final TNonblockingTransport transport; + private final TAsyncClientManager manager; + + public AsyncClient(TProtocolFactory protocolFactory, TAsyncClientManager clientManager, TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + this.manager = clientManager; + this.transport = transport; + } + + public void sayHello(String name, AsyncMethodCallback __resultHandler__) throws TException { + checkReady(); + sayHello_call __method_call__ = new sayHello_call(name, __resultHandler__, this, super.getProtocolFactory(), this.transport); + this.manager.call(__method_call__); + } + + public static class sayHello_call extends TAsyncMethodCall { + private String name; + + public sayHello_call(String name, AsyncMethodCallback __resultHandler__, TAsyncClient __client__, TProtocolFactory __protocolFactory__, TNonblockingTransport __transport__) throws TException { + super(__client__, __protocolFactory__, __transport__, __resultHandler__, false); + this.name = name; + } + + public void write_args(TProtocol __prot__) throws TException { + __prot__.writeMessageBegin(new TMessage("sayHello", TMessageType.CALL, 0)); + sayHello_args __args__ = new sayHello_args(); + __args__.setName(name); + __args__.write(__prot__); + __prot__.writeMessageEnd(); + } + + protected String getResult() throws TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(getFrameBuffer().array()); + TProtocol __prot__ = super.client.getProtocolFactory().getProtocol(__memoryTransport__); + return (new Client(__prot__)).recv_sayHello(); + } + } + public void blocking_call(AsyncMethodCallback __resultHandler__) throws TException { + checkReady(); + blocking_call_call __method_call__ = new blocking_call_call(__resultHandler__, this, super.getProtocolFactory(), this.transport); + this.manager.call(__method_call__); + } + + public static class blocking_call_call extends TAsyncMethodCall { + + public blocking_call_call(AsyncMethodCallback __resultHandler__, TAsyncClient __client__, TProtocolFactory __protocolFactory__, TNonblockingTransport __transport__) throws TException { + super(__client__, __protocolFactory__, __transport__, __resultHandler__, false); + } + + public void write_args(TProtocol __prot__) throws TException { + __prot__.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, 0)); + blocking_call_args __args__ = new blocking_call_args(); + __args__.write(__prot__); + __prot__.writeMessageEnd(); + } + + protected Void getResult() throws TException { + if (getState() != State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(getFrameBuffer().array()); + TProtocol __prot__ = super.client.getProtocolFactory().getProtocol(__memoryTransport__); + + return null; + } + } + } + + + public static class ServiceToClient implements ServiceIface { + private final com.twitter.finagle.Service service; + private final TProtocolFactory protocolFactory; + private final TReusableBuffer tlReusableBuffer; + private final scala.PartialFunction responseClassifier; + + /** + * @deprecated use {@link com.twitter.finagle.thrift.RichClientParam} instead + */ + @Deprecated + public ServiceToClient(com.twitter.finagle.Service service, TProtocolFactory protocolFactory, scala.PartialFunction responseClassifier) { + this(service, com.twitter.finagle.thrift.RichClientParam.apply(protocolFactory, responseClassifier)); + } + + public ServiceToClient(com.twitter.finagle.Service service, com.twitter.finagle.thrift.RichClientParam clientParam) { + + this.service = service; + this.protocolFactory = clientParam.restrictedProtocolFactory(); + this.responseClassifier = clientParam.responseClassifier(); + this.tlReusableBuffer = clientParam.createThriftReusableBuffer(); + } + + public ServiceToClient(com.twitter.finagle.Service service) { + this(service, com.twitter.finagle.thrift.RichClientParam.apply()); + } + + /** + * @deprecated use {@link com.twitter.finagle.thrift.RichClientParam} instead + */ + @Deprecated + public ServiceToClient(com.twitter.finagle.Service service, TProtocolFactory protocolFactory) { + this(service, com.twitter.finagle.thrift.RichClientParam.apply(protocolFactory, com.twitter.finagle.service.ResponseClassifier.Default())); + } + + public Future sayHello(String name) { + try { + TReusableMemoryTransport __memoryTransport__ = tlReusableBuffer.get(); + TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); + __prot__.writeMessageBegin(new TMessage("sayHello", TMessageType.CALL, 0)); + sayHello_args __args__ = new sayHello_args(); + __args__.setName(name); + + Function> replyDeserializer = + new Function>() { + public com.twitter.util.Try apply(byte[] __buffer__) { + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); + TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); + try { + return new com.twitter.util.Return(((new Client(__prot__)).recv_sayHello())); + } catch (Exception e) { + return new com.twitter.util.Throw(e); + } + } + }; + + ClientDeserializeCtx serdeCtx = new ClientDeserializeCtx<>(__args__, replyDeserializer); + return com.twitter.finagle.context.Contexts.local().let( + ClientDeserializeCtx.Key(), + serdeCtx, + new com.twitter.util.ExceptionalFunction0>() { + public Future applyE() throws TException { + serdeCtx.rpcName("sayHello"); + long start = System.nanoTime(); + __args__.write(__prot__); + __prot__.writeMessageEnd(); + serdeCtx.serializationTime(System.nanoTime() - start); + + byte[] __buffer__ = Arrays.copyOf(__memoryTransport__.getArray(), __memoryTransport__.length()); + final ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); + + Future __done__ = service.apply(__request__); + return __done__.flatMap(new Function>() { + public Future apply(byte[] __buffer__) { + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); + TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); + try { + return Future.value((new Client(__prot__)).recv_sayHello()); + } catch (Exception e) { + return Future.exception(e); + } + } + }); + } + }); + } catch (TException e) { + return Future.exception(e); + } finally { + tlReusableBuffer.reset(); + } + } + public Future blocking_call() { + try { + TReusableMemoryTransport __memoryTransport__ = tlReusableBuffer.get(); + TProtocol __prot__ = this.protocolFactory.getProtocol(__memoryTransport__); + __prot__.writeMessageBegin(new TMessage("blocking_call", TMessageType.CALL, 0)); + blocking_call_args __args__ = new blocking_call_args(); + + Function> replyDeserializer = + new Function>() { + public com.twitter.util.Try apply(byte[] __buffer__) { + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); + TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); + try { + (new Client(__prot__)).recv_blocking_call(); + return new com.twitter.util.Return(null); + } catch (Exception e) { + return new com.twitter.util.Throw(e); + } + } + }; + + ClientDeserializeCtx serdeCtx = new ClientDeserializeCtx<>(__args__, replyDeserializer); + return com.twitter.finagle.context.Contexts.local().let( + ClientDeserializeCtx.Key(), + serdeCtx, + new com.twitter.util.ExceptionalFunction0>() { + public Future applyE() throws TException { + serdeCtx.rpcName("blocking_call"); + long start = System.nanoTime(); + __args__.write(__prot__); + __prot__.writeMessageEnd(); + serdeCtx.serializationTime(System.nanoTime() - start); + + byte[] __buffer__ = Arrays.copyOf(__memoryTransport__.getArray(), __memoryTransport__.length()); + final ThriftClientRequest __request__ = new ThriftClientRequest(__buffer__, false); + + Future __done__ = service.apply(__request__); + return __done__.flatMap(new Function>() { + public Future apply(byte[] __buffer__) { + TMemoryInputTransport __memoryTransport__ = new TMemoryInputTransport(__buffer__); + TProtocol __prot__ = ServiceToClient.this.protocolFactory.getProtocol(__memoryTransport__); + try { + (new Client(__prot__)).recv_blocking_call(); + return Future.value(null); + } catch (Exception e) { + return Future.exception(e); + } + } + }); + } + }); + } catch (TException e) { + return Future.exception(e); + } finally { + tlReusableBuffer.reset(); + } + } + } + + public static class Processor implements TProcessor { + public Processor(Iface iface) + { + iface_ = iface; + processMap_.put("sayHello", new sayHello()); + processMap_.put("blocking_call", new blocking_call()); + } + + protected static interface ProcessFunction { + public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException; + } + + private Iface iface_; + protected final HashMap processMap_ = new HashMap(); + + public boolean process(TProtocol iprot, TProtocol oprot) throws TException + { + TMessage msg = iprot.readMessageBegin(); + ProcessFunction fn = processMap_.get(msg.name); + if (fn == null) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); + oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return true; + } + fn.process(msg.seqid, iprot, oprot); + return true; + } + + private class sayHello implements ProcessFunction { + public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException + { + sayHello_args args = new sayHello_args(); + try { + args.read(iprot); + } catch (TProtocolException e) { + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); + oprot.writeMessageBegin(new TMessage("sayHello", TMessageType.EXCEPTION, seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } + iprot.readMessageEnd(); + sayHello_result result = new sayHello_result(); + result.success = iface_.sayHello(args.name); + + oprot.writeMessageBegin(new TMessage("sayHello", TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } + } + private class blocking_call implements ProcessFunction { + public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException + { + blocking_call_args args = new blocking_call_args(); + try { + args.read(iprot); + } catch (TProtocolException e) { + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()); + oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.EXCEPTION, seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } + iprot.readMessageEnd(); + blocking_call_result result = new blocking_call_result(); + iface_.blocking_call(); + + oprot.writeMessageBegin(new TMessage("blocking_call", TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } + } + } + + public static class Service extends com.twitter.finagle.Service { + private final ServiceIface iface; + private final com.twitter.finagle.Filter.TypeAgnostic filters; + private final TProtocolFactory protocolFactory; + private final String serviceName; + private final TReusableBuffer tlReusableBuffer; + protected HashMap, byte[]>> serviceMap = + new HashMap, byte[]>>(); + public Service(final ServiceIface iface, final com.twitter.finagle.Filter.TypeAgnostic filters, final com.twitter.finagle.thrift.RichServerParam serverParam) { + this.iface = iface; + this.filters = filters; + this.protocolFactory = serverParam.restrictedProtocolFactory(); + this.serviceName = serverParam.serviceName(); + this.tlReusableBuffer = new TReusableBuffer(512, serverParam.maxThriftBufferSize()); + createMethods(); + } + + public Service(final ServiceIface iface, final com.twitter.finagle.thrift.RichServerParam serverParam) { + this(iface, com.twitter.finagle.Filter.typeAgnosticIdentity(), serverParam); + } + + public Service(final ServiceIface iface) { + this(iface, new com.twitter.finagle.thrift.RichServerParam()); + } + + /** + * @deprecated use {@link com.twitter.finagle.thrift.RichServerParam} instead + */ + @Deprecated + public Service(final ServiceIface iface, final TProtocolFactory protocolFactory) { + this(iface, new com.twitter.finagle.thrift.RichServerParam(protocolFactory)); + } + + private void createMethods() { + + class sayHelloService { + private final com.twitter.finagle.SimpleFilter, byte[]> protocolExnFilter = new com.twitter.finagle.SimpleFilter, byte[]>() { + @Override + public Future apply(scala.Tuple2 request, com.twitter.finagle.Service, byte[]> service) { + return service.apply(request).rescue(new Function>() { + @Override + public Future apply(Throwable e) { + TProtocol iprot = request._1(); + Integer seqid = request._2(); + if (e instanceof TProtocolException) { + try { + iprot.readMessageEnd(); + setReqRepContext(request, new com.twitter.util.Throw(new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()))); + return exception("sayHello", seqid, TApplicationException.PROTOCOL_ERROR, e.getMessage()); + } catch (Exception e1) { + setReqRepContext(request, new com.twitter.util.Throw(e1)); + return Future.exception(e1); + } + } else { + setReqRepContext(request, new com.twitter.util.Throw(e)); + return Future.exception(e); + } + } + }); + } + }; + + private final com.twitter.finagle.Filter, byte[], sayHello_args, String> serdeFilter = new com.twitter.finagle.Filter, byte[], sayHello_args, String>() { + @Override + public Future apply(scala.Tuple2 request, com.twitter.finagle.Service service) { + TProtocol iprot = request._1(); + Integer seqid = request._2(); + sayHello_args args = new sayHello_args(); + + try { + long start = System.nanoTime(); + args.read(iprot); + iprot.readMessageEnd(); + com.twitter.finagle.tracing.Trace.recordBinary("srv/request_deserialization_ns", System.nanoTime() - start); + } catch (Exception e) { + return Future.exception(e); + } + + Future res = com.twitter.finagle.context.Contexts.local().let( + com.twitter.finagle.thrift.MethodMetadata.Key(), + new com.twitter.finagle.thrift.MethodMetadata( + "sayHello", + serviceName, + sayHello_args.class, + sayHello_result.class), + new scala.runtime.AbstractFunction0>() { + @Override + public Future apply() { + return service.apply(args); + } + }); + sayHello_result result = new sayHello_result(); + return res.flatMap(new Function>() { + @Override + public Future apply(String value) { + result.success = value; + result.setSuccessIsSet(true); + setReqRepContext(args, new com.twitter.util.Return(value)); + return reply("sayHello", seqid, result); + } + }).rescue(new Function>() { + @Override + public Future apply(Throwable t) { + setReqRepContext(args, new com.twitter.util.Throw(t)); + return Future.exception(t); + } + }); + } + }; + + private final com.twitter.finagle.Service methodService = new com.twitter.finagle.Service() { + @Override + public Future apply(sayHello_args args) { + Future future = iface.sayHello(args.name); + return future; + } + }; + + private final com.twitter.finagle.Service, byte[]> getService = + protocolExnFilter.andThen(serdeFilter).andThen(filters.toFilter()).andThen(methodService); + } + + serviceMap.put("sayHello", (new sayHelloService()).getService); + + class blocking_callService { + private final com.twitter.finagle.SimpleFilter, byte[]> protocolExnFilter = new com.twitter.finagle.SimpleFilter, byte[]>() { + @Override + public Future apply(scala.Tuple2 request, com.twitter.finagle.Service, byte[]> service) { + return service.apply(request).rescue(new Function>() { + @Override + public Future apply(Throwable e) { + TProtocol iprot = request._1(); + Integer seqid = request._2(); + if (e instanceof TProtocolException) { + try { + iprot.readMessageEnd(); + setReqRepContext(request, new com.twitter.util.Throw(new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage()))); + return exception("blocking_call", seqid, TApplicationException.PROTOCOL_ERROR, e.getMessage()); + } catch (Exception e1) { + setReqRepContext(request, new com.twitter.util.Throw(e1)); + return Future.exception(e1); + } + } else { + setReqRepContext(request, new com.twitter.util.Throw(e)); + return Future.exception(e); + } + } + }); + } + }; + + private final com.twitter.finagle.Filter, byte[], blocking_call_args, Void> serdeFilter = new com.twitter.finagle.Filter, byte[], blocking_call_args, Void>() { + @Override + public Future apply(scala.Tuple2 request, com.twitter.finagle.Service service) { + TProtocol iprot = request._1(); + Integer seqid = request._2(); + blocking_call_args args = new blocking_call_args(); + + try { + long start = System.nanoTime(); + args.read(iprot); + iprot.readMessageEnd(); + com.twitter.finagle.tracing.Trace.recordBinary("srv/request_deserialization_ns", System.nanoTime() - start); + } catch (Exception e) { + return Future.exception(e); + } + + Future res = com.twitter.finagle.context.Contexts.local().let( + com.twitter.finagle.thrift.MethodMetadata.Key(), + new com.twitter.finagle.thrift.MethodMetadata( + "blocking_call", + serviceName, + blocking_call_args.class, + blocking_call_result.class), + new scala.runtime.AbstractFunction0>() { + @Override + public Future apply() { + return service.apply(args); + } + }); + blocking_call_result result = new blocking_call_result(); + return res.flatMap(new Function>() { + @Override + public Future apply(Void value) { + setReqRepContext(args, new com.twitter.util.Return(value)); + return reply("blocking_call", seqid, result); + } + }).rescue(new Function>() { + @Override + public Future apply(Throwable t) { + setReqRepContext(args, new com.twitter.util.Throw(t)); + return Future.exception(t); + } + }); + } + }; + + private final com.twitter.finagle.Service methodService = new com.twitter.finagle.Service() { + @Override + public Future apply(blocking_call_args args) { + Future future = iface.blocking_call(); + return future; + } + }; + + private final com.twitter.finagle.Service, byte[]> getService = + protocolExnFilter.andThen(serdeFilter).andThen(filters.toFilter()).andThen(methodService); + } + + serviceMap.put("blocking_call", (new blocking_callService()).getService); + } + + private void setReqRepContext(Object req, com.twitter.util.Try rep) { + scala.Option serdeCtx = com.twitter.finagle.context.Contexts.local().get(ServerToReqRep.Key()); + if (serdeCtx.nonEmpty()) { + serdeCtx.get().setReqRep(new com.twitter.finagle.service.ReqRep(req, rep)); + } + } + + public Future apply(byte[] request) { + TTransport inputTransport = new TMemoryInputTransport(request); + TProtocol iprot = protocolFactory.getProtocol(inputTransport); + + TMessage msg; + try { + msg = iprot.readMessageBegin(); + } catch (Exception e) { + return Future.exception(e); + } + + com.twitter.finagle.Service, byte[]> svc = serviceMap.get(msg.name); + if (svc == null) { + try { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'"); + TReusableMemoryTransport memoryBuffer = tlReusableBuffer.get(); + TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return Future.value(Arrays.copyOf(memoryBuffer.getArray(), memoryBuffer.length())); + } catch (Exception e) { + return Future.exception(e); + } finally { + tlReusableBuffer.reset(); + } + } + + return svc.apply(new scala.Tuple2(iprot, msg.seqid)); + } + + private Future reply(String name, Integer seqid, TBase result) { + try { + long start = System.nanoTime(); + TReusableMemoryTransport memoryBuffer = tlReusableBuffer.get(); + TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + + oprot.writeMessageBegin(new TMessage(name, TMessageType.REPLY, seqid)); + result.write(oprot); + oprot.writeMessageEnd(); + com.twitter.finagle.tracing.Trace.recordBinary("srv/response_serialization_ns", System.nanoTime() - start); + + return Future.value(Arrays.copyOf(memoryBuffer.getArray(), memoryBuffer.length())); + } catch (Exception e) { + return Future.exception(e); + } finally { + tlReusableBuffer.reset(); + } + } + + private Future exception(String name, Integer seqid, Integer code, String message) { + try { + TApplicationException x = new TApplicationException(code, message); + TReusableMemoryTransport memoryBuffer = tlReusableBuffer.get(); + TProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + + oprot.writeMessageBegin(new TMessage(name, TMessageType.EXCEPTION, seqid)); + x.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + byte[] buffer = Arrays.copyOf(memoryBuffer.getArray(), memoryBuffer.length()); + return Future.value(buffer); + } catch (Exception e1) { + return Future.exception(e1); + } finally { + tlReusableBuffer.reset(); + } + } + } + + public static class sayHello_args implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("sayHello_args"); + + private static final TField NAME_FIELD_DESC = new TField("name", TType.STRING, (short)1); + + + public String name; + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements TFieldIdEnum { + NAME((short)1, "name"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // NAME + return NAME; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + + // isset id assignments + + public static final Map<_Fields, FieldMetaData> metaDataMap; + + /** + * FieldValueMetaData.type returns TType.STRING for both string and binary field values. + * This set can be used to determine if a FieldValueMetaData with type TType.STRING is actually + * declared as binary in the idl file. + */ + public static final Set binaryFieldValueMetaDatas; + + private static FieldValueMetaData registerBinaryFieldValueMetaData(FieldValueMetaData f, Set binaryFieldValues) { + binaryFieldValues.add(f); + return f; + } + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + Set tmpSet = new HashSet(); + tmpMap.put(_Fields.NAME, new FieldMetaData("name", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + binaryFieldValueMetaDatas = Collections.unmodifiableSet(tmpSet); + FieldMetaData.addStructMetaDataMap(sayHello_args.class, metaDataMap); + } + + /** + * Returns a map of the annotations and their values for this struct declaration. + * See fieldAnnotations or valueAnnotations for the annotations attached to struct fields + * or enum values. + */ + public static final Map structAnnotations; + static { + structAnnotations = Collections.emptyMap(); + } + + /** + * Returns a map of the annotations for each of this struct's fields, keyed by the field. + * See structAnnotations for the annotations attached to this struct's declaration. + */ + public static final Map<_Fields, Map> fieldAnnotations; + static { + fieldAnnotations = Collections.emptyMap(); + } + + /** + * Returns the set of fields that have a configured default value. + * The default values for these fields can be obtained by + * instantiating this class with the default constructor. + */ + public static final Set<_Fields> hasDefaultValue; + static { + Set<_Fields> tmp = EnumSet.noneOf(_Fields.class); + hasDefaultValue = Collections.unmodifiableSet(tmp); + } + + + public sayHello_args() { + } + + public sayHello_args( + String name) + { + this(); + this.name = name; + } + + /** + * Performs a deep copy on other. + */ + public sayHello_args(sayHello_args other) { + if (other.isSetName()) { + this.name = other.name; + } + } + + public static List validateNewInstance(sayHello_args item) { + final List buf = new ArrayList(); + + return buf; + } + + public sayHello_args deepCopy() { + return new sayHello_args(this); + } + + @java.lang.Override + public void clear() { + this.name = null; + } + + public String getName() { + return this.name; + } + + public sayHello_args setName(String name) { + this.name = name; + + return this; + } + + public void unsetName() { + this.name = null; + } + + /** Returns true if field name is set (has been assigned a value) and false otherwise */ + public boolean isSetName() { + return this.name != null; + } + + public void setNameIsSet(boolean value) { + if (!value) { + this.name = null; + } + } + + @SuppressWarnings("unchecked") + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case NAME: + if (value == null) { + unsetName(); + } else { + setName((String)value); + } + break; + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case NAME: + return getName(); + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case NAME: + return isSetName(); + } + throw new IllegalStateException(); + } + + @java.lang.Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof sayHello_args) + return this.equals((sayHello_args)that); + return false; + } + + public boolean equals(sayHello_args that) { + if (that == null) + return false; + boolean this_present_name = true && this.isSetName(); + boolean that_present_name = true && that.isSetName(); + if (this_present_name || that_present_name) { + if (!(this_present_name && that_present_name)) + return false; + if (!this.name.equals(that.name)) + return false; + } + + return true; + } + + @java.lang.Override + public int hashCode() { + int hashCode = 1; + if (isSetName()) { + hashCode = 31 * hashCode + name.hashCode(); + } + return hashCode; + } + + public int compareTo(sayHello_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + sayHello_args typedOther = (sayHello_args)other; + + lastComparison = Boolean.valueOf(isSetName()).compareTo(typedOther.isSetName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetName()) { + lastComparison = TBaseHelper.compareTo(this.name, typedOther.name); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 1: // NAME + if (field.type == TType.STRING) { + this.name = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + TProtocolUtil.skip(iprot, field.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (this.name != null) { + oprot.writeFieldBegin(NAME_FIELD_DESC); + oprot.writeString(this.name); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @java.lang.Override + public String toString() { + StringBuilder sb = new StringBuilder("sayHello_args("); + boolean first = true; + sb.append("name:"); + if (this.name == null) { + sb.append("null"); + } else { + sb.append(this.name); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } +} + + + public static class sayHello_result implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("sayHello_result"); + + private static final TField SUCCESS_FIELD_DESC = new TField("success", TType.STRING, (short)0); + + + public String success; + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + + // isset id assignments + + public static final Map<_Fields, FieldMetaData> metaDataMap; + + /** + * FieldValueMetaData.type returns TType.STRING for both string and binary field values. + * This set can be used to determine if a FieldValueMetaData with type TType.STRING is actually + * declared as binary in the idl file. + */ + public static final Set binaryFieldValueMetaDatas; + + private static FieldValueMetaData registerBinaryFieldValueMetaData(FieldValueMetaData f, Set binaryFieldValues) { + binaryFieldValues.add(f); + return f; + } + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + Set tmpSet = new HashSet(); + tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success", TFieldRequirementType.DEFAULT, + new FieldValueMetaData(TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + binaryFieldValueMetaDatas = Collections.unmodifiableSet(tmpSet); + FieldMetaData.addStructMetaDataMap(sayHello_result.class, metaDataMap); + } + + /** + * Returns a map of the annotations and their values for this struct declaration. + * See fieldAnnotations or valueAnnotations for the annotations attached to struct fields + * or enum values. + */ + public static final Map structAnnotations; + static { + structAnnotations = Collections.emptyMap(); + } + + /** + * Returns a map of the annotations for each of this struct's fields, keyed by the field. + * See structAnnotations for the annotations attached to this struct's declaration. + */ + public static final Map<_Fields, Map> fieldAnnotations; + static { + fieldAnnotations = Collections.emptyMap(); + } + + /** + * Returns the set of fields that have a configured default value. + * The default values for these fields can be obtained by + * instantiating this class with the default constructor. + */ + public static final Set<_Fields> hasDefaultValue; + static { + Set<_Fields> tmp = EnumSet.noneOf(_Fields.class); + hasDefaultValue = Collections.unmodifiableSet(tmp); + } + + + public sayHello_result() { + } + + public sayHello_result( + String success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public sayHello_result(sayHello_result other) { + if (other.isSetSuccess()) { + this.success = other.success; + } + } + + public static List validateNewInstance(sayHello_result item) { + final List buf = new ArrayList(); + + return buf; + } + + public sayHello_result deepCopy() { + return new sayHello_result(this); + } + + @java.lang.Override + public void clear() { + this.success = null; + } + + public String getSuccess() { + return this.success; + } + + public sayHello_result setSuccess(String success) { + this.success = success; + + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + @SuppressWarnings("unchecked") + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((String)value); + } + break; + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @java.lang.Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof sayHello_result) + return this.equals((sayHello_result)that); + return false; + } + + public boolean equals(sayHello_result that) { + if (that == null) + return false; + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + return true; + } + + @java.lang.Override + public int hashCode() { + int hashCode = 1; + if (isSetSuccess()) { + hashCode = 31 * hashCode + success.hashCode(); + } + return hashCode; + } + + public int compareTo(sayHello_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + sayHello_result typedOther = (sayHello_result)other; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = TBaseHelper.compareTo(this.success, typedOther.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case 0: // SUCCESS + if (field.type == TType.STRING) { + this.success = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + TProtocolUtil.skip(iprot, field.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + oprot.writeStructBegin(STRUCT_DESC); + if (this.isSetSuccess()) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeString(this.success); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @java.lang.Override + public String toString() { + StringBuilder sb = new StringBuilder("sayHello_result("); + boolean first = true; + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } +} + + + + public static class blocking_call_args implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("blocking_call_args"); + + + + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + + + public static final Map<_Fields, FieldMetaData> metaDataMap; + + /** + * FieldValueMetaData.type returns TType.STRING for both string and binary field values. + * This set can be used to determine if a FieldValueMetaData with type TType.STRING is actually + * declared as binary in the idl file. + */ + public static final Set binaryFieldValueMetaDatas; + + private static FieldValueMetaData registerBinaryFieldValueMetaData(FieldValueMetaData f, Set binaryFieldValues) { + binaryFieldValues.add(f); + return f; + } + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + Set tmpSet = new HashSet(); + metaDataMap = Collections.unmodifiableMap(tmpMap); + binaryFieldValueMetaDatas = Collections.unmodifiableSet(tmpSet); + FieldMetaData.addStructMetaDataMap(blocking_call_args.class, metaDataMap); + } + + /** + * Returns a map of the annotations and their values for this struct declaration. + * See fieldAnnotations or valueAnnotations for the annotations attached to struct fields + * or enum values. + */ + public static final Map structAnnotations; + static { + structAnnotations = Collections.emptyMap(); + } + + /** + * Returns a map of the annotations for each of this struct's fields, keyed by the field. + * See structAnnotations for the annotations attached to this struct's declaration. + */ + public static final Map<_Fields, Map> fieldAnnotations; + static { + fieldAnnotations = Collections.emptyMap(); + } + + /** + * Returns the set of fields that have a configured default value. + * The default values for these fields can be obtained by + * instantiating this class with the default constructor. + */ + public static final Set<_Fields> hasDefaultValue; + static { + Set<_Fields> tmp = EnumSet.noneOf(_Fields.class); + hasDefaultValue = Collections.unmodifiableSet(tmp); + } + + + public blocking_call_args() { + } + + + /** + * Performs a deep copy on other. + */ + public blocking_call_args(blocking_call_args other) { + } + + public static List validateNewInstance(blocking_call_args item) { + final List buf = new ArrayList(); + + return buf; + } + + public blocking_call_args deepCopy() { + return new blocking_call_args(this); + } + + @java.lang.Override + public void clear() { + } + + @SuppressWarnings("unchecked") + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @java.lang.Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof blocking_call_args) + return this.equals((blocking_call_args)that); + return false; + } + + public boolean equals(blocking_call_args that) { + if (that == null) + return false; + + return true; + } + + @java.lang.Override + public int hashCode() { + int hashCode = 1; + return hashCode; + } + + public int compareTo(blocking_call_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + blocking_call_args typedOther = (blocking_call_args)other; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + default: + TProtocolUtil.skip(iprot, field.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @java.lang.Override + public String toString() { + StringBuilder sb = new StringBuilder("blocking_call_args("); + boolean first = true; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } +} + + + public static class blocking_call_result implements TBase, java.io.Serializable, Cloneable { + private static final TStruct STRUCT_DESC = new TStruct("blocking_call_result"); + + + + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + + + public static final Map<_Fields, FieldMetaData> metaDataMap; + + /** + * FieldValueMetaData.type returns TType.STRING for both string and binary field values. + * This set can be used to determine if a FieldValueMetaData with type TType.STRING is actually + * declared as binary in the idl file. + */ + public static final Set binaryFieldValueMetaDatas; + + private static FieldValueMetaData registerBinaryFieldValueMetaData(FieldValueMetaData f, Set binaryFieldValues) { + binaryFieldValues.add(f); + return f; + } + + static { + Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class); + Set tmpSet = new HashSet(); + metaDataMap = Collections.unmodifiableMap(tmpMap); + binaryFieldValueMetaDatas = Collections.unmodifiableSet(tmpSet); + FieldMetaData.addStructMetaDataMap(blocking_call_result.class, metaDataMap); + } + + /** + * Returns a map of the annotations and their values for this struct declaration. + * See fieldAnnotations or valueAnnotations for the annotations attached to struct fields + * or enum values. + */ + public static final Map structAnnotations; + static { + structAnnotations = Collections.emptyMap(); + } + + /** + * Returns a map of the annotations for each of this struct's fields, keyed by the field. + * See structAnnotations for the annotations attached to this struct's declaration. + */ + public static final Map<_Fields, Map> fieldAnnotations; + static { + fieldAnnotations = Collections.emptyMap(); + } + + /** + * Returns the set of fields that have a configured default value. + * The default values for these fields can be obtained by + * instantiating this class with the default constructor. + */ + public static final Set<_Fields> hasDefaultValue; + static { + Set<_Fields> tmp = EnumSet.noneOf(_Fields.class); + hasDefaultValue = Collections.unmodifiableSet(tmp); + } + + + public blocking_call_result() { + } + + + /** + * Performs a deep copy on other. + */ + public blocking_call_result(blocking_call_result other) { + } + + public static List validateNewInstance(blocking_call_result item) { + final List buf = new ArrayList(); + + return buf; + } + + public blocking_call_result deepCopy() { + return new blocking_call_result(this); + } + + @java.lang.Override + public void clear() { + } + + @SuppressWarnings("unchecked") + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @java.lang.Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof blocking_call_result) + return this.equals((blocking_call_result)that); + return false; + } + + public boolean equals(blocking_call_result that) { + if (that == null) + return false; + + return true; + } + + @java.lang.Override + public int hashCode() { + int hashCode = 1; + return hashCode; + } + + public int compareTo(blocking_call_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + blocking_call_result typedOther = (blocking_call_result)other; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public void read(TProtocol iprot) throws TException { + TField field; + iprot.readStructBegin(); + while (true) + { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + default: + TProtocolUtil.skip(iprot, field.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + public void write(TProtocol oprot) throws TException { + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + @java.lang.Override + public String toString() { + StringBuilder sb = new StringBuilder("blocking_call_result("); + boolean first = true; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws TException { + // check for required fields + } +} + + + +} diff --git a/src/main/java/org/example/HelloServiceImpl.java b/src/main/java/org/example/HelloServiceImpl.java new file mode 100644 index 0000000..334715d --- /dev/null +++ b/src/main/java/org/example/HelloServiceImpl.java @@ -0,0 +1,21 @@ +package org.example; + +import com.twitter.util.Future; +import org.example.HelloService; + +public class HelloServiceImpl implements HelloService.ServiceIface { + + @Override + public Future sayHello(String name) { + // Implement the logic for sayHello method + return Future.value("Hello, " + name + "!"); + } + + @Override + public Future blocking_call() { + // Implement the logic for blocking_call method + // This method is typically used for operations that may block + // Implement the blocking logic here + return Future.Done().voided(); + } +} diff --git a/src/main/thrift/hello.thrift b/src/main/thrift/hello.thrift new file mode 100644 index 0000000..550819b --- /dev/null +++ b/src/main/thrift/hello.thrift @@ -0,0 +1,6 @@ +namespace java org.example + +service HelloService { + string sayHello(1:string name) + void blocking_call() +} \ No newline at end of file