diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0e1161 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ + + +thrift-server/target +thrift-client/target +kafka-consumer/target +clients-simulator/target +infra/target + + +clients-simulator/dependency-reduced-pom.xml +kafka-consumer/dependency-reduced-pom.xml +thrift-server/dependency-reduced-pom.xml + +.idea/ + +infra/out/* \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..42c1d9b --- /dev/null +++ b/README.md @@ -0,0 +1,180 @@ + +# Logging System + + +##### Assignee: Nikolaos Christidis (nick.christidis@yahoo.com) + + +#### Prerequisites + +* Maven +* JDK 11 +* Apache Thrift + +#### Components of the Platform + +1. Module [thrift-client](thrift-client/README.md) is the program that we use to send the logging +event to thrift-server. + +2. Module [thrift-server](thrift-server/README.md) implements the other end of the thrift API and +sends logging events to Kafka. + +3. Module [kafka-consumer](kafka-consumer/README.md) reads events from Kafka and writes/materializes them to +Cassandra. + +4. Module [clients-simulator](clients-simulator/README.md) which produces traffic via using `thrift-client` library to send log events/messages. + +5. Module [infra](infra/README.md) which provides the necessary docker images in order to setup the infrastructure needed (Kafka, Cassandra) + +```text + + Producer side: + + application_uses { [thrift-client] } ---sends log message---> [thrift-server] ---sends log message---> [kafka] + + + + Consumer side: + + daemon_or_scheduler_or_something_similar { [kafka-consumer] } + <--- reads log message from --- [kafka] + --- materializes log message to ---> [cassandra] +``` + + +#### Important Notes: + +* (Selected by default) In order to use [LoggingEventServiceAsyncClient](thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceAsyncClient.scala) you should use +the following server flavour: [THREADED_SELECTOR_SERVER](thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/ServerFlavour.java) for the thrift-server. + + +#### Logging Event Definition + +* [logging_event_service.thrift](thrift-server/src/main/java/logging_event_service.thrift) + + + +#### Installing Thrift - Linux + +* `sudo apt-get update -y` +* `sudo apt-get install -y thrift-compiler` + + +#### Setup instructions / Run platform + +* Visit [infra](infra/README.md) and run the docker-containers + +* Make sure your maven points jdk11, to test, execute: `mvn -v`, you should see something like this output: + * ```text + mnchristidis@nchristidis-GL502VMK ~/Desktop/pollfish-chriniko $ mvn -v + Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) + Maven home: /opt/apache/maven-3.6.3 + Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 + Default locale: en_US, platform encoding: UTF-8 + OS name: "linux", version: "5.3.0-45-generic", arch: "amd64", family: "unix" + + ``` + +* Now, in the root folder, execute: `mvn clean install` + + +* Run thrift-server first: + * ` cd thrift-server/` + * `java -jar target/thrift-server-1.0-SNAPSHOT.jar` + + * Output: + ```text + nchristidis@nchristidis-GL502VMK ~/Desktop/pollfish-chriniko/thrift-server $ java -jar target/thrift-server-1.0-SNAPSHOT.jar + [INFO ] 2020-11-26 13:24:34.855 [main] LoggingEventServer - will use server flavour: THREADED_SELECTOR_SERVER + SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". + SLF4J: Defaulting to no-operation (NOP) logger implementation + SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. + [INFO ] 2020-11-26 13:24:35.039 [main] LoggingEventServer - Starting the server... + [INFO ] 2020-11-26 13:24:35.039 [server-status-checker] LoggingEventServer - server is not up and running... will ping again... + [INFO ] 2020-11-26 13:24:36.289 [server-status-checker] LoggingEventServer - server is up and running + + ``` + +* Run clients-simulator: + * ` cd clients-simulator/` + * ` java -jar target/clients-simulator-1.0-SNAPSHOT.jar ` + + * Output: + ```text + nchristidis@nchristidis-GL502VMK ~/Desktop/pollfish-chriniko/clients-simulator $ java -jar target/clients-simulator-1.0-SNAPSHOT.jar + SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". + SLF4J: Defaulting to no-operation (NOP) logger implementation + SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. + [INFO ] 2020-11-26 13:36:03.615 [client-sim-coord-4] ClientSimulationsCoordinator - clientFlow success, message: + LoggingEvent(id:20ffb16e-b930-4167-89de-1a975cf8a454, origin:monitor_service_0, time:1606390563140, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:479dde6d-dbc4-4e0b-bf83-9adfe61acdac, origin:wallet_service_0, time:1606390563347, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:a958f6a5-2e23-400c-8da0-621f0a795f7d, origin:user_service_1, time:1606390563482, metadata:{somekey1=somevalue1, somekey2=somevalue2, somekey3=somevalue3}, m:)>, priority:CRITICAL) + + [INFO ] 2020-11-26 13:36:03.615 [client-sim-coord-10] ClientSimulationsCoordinator - clientFlow success, message: + LoggingEvent(id:20ffb16e-b930-4167-89de-1a975cf8a454, origin:monitor_service_0, time:1606390563140, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:479dde6d-dbc4-4e0b-bf83-9adfe61acdac, origin:wallet_service_0, time:1606390563347, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:a958f6a5-2e23-400c-8da0-621f0a795f7d, origin:user_service_1, time:1606390563482, metadata:{somekey1=somevalue1, somekey2=somevalue2, somekey3=somevalue3}, m:)>, priority:CRITICAL) + + [INFO ] 2020-11-26 13:36:03.615 [client-sim-coord-5] ClientSimulationsCoordinator - clientFlow success, message: + LoggingEvent(id:20ffb16e-b930-4167-89de-1a975cf8a454, origin:monitor_service_0, time:1606390563140, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:479dde6d-dbc4-4e0b-bf83-9adfe61acdac, origin:wallet_service_0, time:1606390563347, metadata:{}, m:, priority:NORMAL) + LoggingEvent(id:a958f6a5-2e23-400c-8da0-621f0a795f7d, origin:user_service_1, time:1606390563482, metadata:{somekey1=somevalue1, somekey2=somevalue2, somekey3=somevalue3}, m:)>, priority:CRITICAL) + + ``` + + +* Run kafka-consumer: + * `cd kafka-consumer/` + * `java -jar target/kafka-consumer-1.0-SNAPSHOT.jar` + + * Output: + + ```text + + nchristidis@nchristidis-GL502VMK ~/Desktop/pollfish-chriniko/kafka-consumer $ java -jar target/kafka-consumer-1.0-SNAPSHOT.jar + SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". + SLF4J: Defaulting to no-operation (NOP) logger implementation + SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. + WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance. + [DEBUG] 2020-11-26 13:43:45.189 [main] CassandraStore - will execute query: CREATE KEYSPACE IF NOT EXISTS poll_fish WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; + [DEBUG] 2020-11-26 13:43:45.209 [main] CassandraStore - will execute query: USE poll_fish; + [DEBUG] 2020-11-26 13:43:45.215 [main] CassandraStore - will execute query: drop table if exists logging_evts_by_type_ord_time_desc; + [DEBUG] 2020-11-26 13:43:46.882 [main] CassandraStore - will execute query: create table logging_evts_by_type_ord_time_desc( version int, id uuid, origin text, time timestamp, metadata map, type text, priority text, payload text, primary key ( type, time )) WITH CLUSTERING ORDER BY (time desc); + [DEBUG] 2020-11-26 13:43:48.027 [main] CassandraStore - will execute query: drop table if exists logging_evts_by_priority_ord_time_desc; + [DEBUG] 2020-11-26 13:43:49.344 [main] CassandraStore - will execute query: create table logging_evts_by_priority_ord_time_desc( version int, id uuid, origin text, time timestamp, metadata map, type text, priority text, payload text, primary key ( priority, time )) WITH CLUSTERING ORDER BY (time desc); + [DEBUG] 2020-11-26 13:43:50.565 [main] CassandraStore - will execute query: drop table if exists logging_evts_by_priority_by_type_ord_time_desc; + [DEBUG] 2020-11-26 13:43:51.891 [main] CassandraStore - will execute query: create table logging_evts_by_priority_by_type_ord_time_desc( version int, id uuid, origin text, time timestamp, metadata map, type text, priority text, payload text, primary key ( (priority, type), time )) WITH CLUSTERING ORDER BY (time desc); + [DEBUG] 2020-11-26 13:43:53.035 [main] CassandraStore - will execute query: drop table if exists logging_evts_by_or_by_prio_by_typ_ord_t_desc; + [DEBUG] 2020-11-26 13:43:54.480 [main] CassandraStore - will execute query: create table logging_evts_by_or_by_prio_by_typ_ord_t_desc( version int, id uuid, origin text, time timestamp, metadata map, type text, priority text, payload text, primary key ( (origin, priority, type), time )) WITH CLUSTERING ORDER BY (time desc); + [DEBUG] 2020-11-26 13:43:55.636 [main] CassandraStore - will execute query: drop table if exists logging_evts_by_or_ord_prio_typ_t_desc; + [DEBUG] 2020-11-26 13:43:56.993 [main] CassandraStore - will execute query: create table logging_evts_by_or_ord_prio_typ_t_desc( version int, id uuid, origin text, time timestamp, metadata map, type text, priority text, payload text, primary key ( (origin), priority, type, time )) WITH CLUSTERING ORDER BY (priority asc, type asc, time desc); + [INFO ] 2020-11-26 13:43:58.672 [main] BootstrapKafkaConsumer$ - controls created: 1 + [INFO] [11/26/2020 13:43:58.682] [logging-events-consumer-akka.actor.default-dispatcher-4] [SingleSourceLogic(akka://logging-events-consumer)] [4cc11] Starting. StageActor Actor[akka://logging-events-consumer/system/StreamSupervisor-0/$$a#608205030] + [DEBUG] 2020-11-26 13:43:59.709 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-32] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:a650fd9e-468d-46f0-8917-edbd9eeea0d6, origin:wallet_service_2, time:1606332814207, metadata:{somekey1=somevalue1, somekey2=somevalue2, somekey3=somevalue3}, m:, priority:NORMAL) + [DEBUG] 2020-11-26 13:43:59.709 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-26] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:c3356ad2-c1a1-4b72-b658-1477d29795f7, origin:wallet_service_2, time:1606330544501, metadata:{}, m:, priority:NORMAL) + [DEBUG] 2020-11-26 13:43:59.710 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-38] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:52a028e2-81cc-41ca-8da1-aa5cc547e4df, origin:wallet_service_2, time:1606351727106, metadata:{}, m:, priority:NORMAL) + [DEBUG] 2020-11-26 13:43:59.710 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-24] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:7b17d2fe-f4e6-4b56-a8c3-66b6499c907b, origin:monitor_service_1, time:1606330542972, metadata:{somekey1=somevalue1, somekey2=somevalue2, somekey3=somevalue3}, m:, priority:CRITICAL) + [DEBUG] 2020-11-26 13:43:59.710 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-25] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:e998f0b4-e44c-40d8-8d32-6586964a1fc8, origin:wallet_service_1, time:1606330543099, metadata:{}, m:, priority:NORMAL) + [DEBUG] 2020-11-26 13:43:59.710 [logging-events-consumer-akka.kafka.io-blocking-dispatcher-36] LoggingEventDeserializer - >>>> event consumed: LoggingEvent(id:3498fb2f-6d15-4150-9bb6-49ef43fcda14, origin:monitor_service_2, time:1606351711683, metadata:{}, m:, priority:NORMAL) + + ``` + +#### Future Work / TODOs + +* During to personal time limitation, no unit tests and integration tests have been written which is UNACCEPTABLE +for real production systems. + * first thing to do, is to create an it-suite maven module where it will have logic to test all the parts of the platform + * then we can proceed with integration tests per module and unit tests + * inverted pyramid of testing is what most of times I prefer. + +* Create 3-node cassandra cluster with docker-containers and produce heavy traffic to check how it behaves, experiment, etc. + +* Benchmark, check behaviour with a tool such as VisualVM + +* If we see that our thrift-server cannot hold the load, we can run multiple +thrift-servers (JVM processes) and made modifications to store the incoming log-event message to a distributed queue +provided from implementers such as Hazelcast (https://docs.hazelcast.org/docs/latest/manual/html-single/#queue), so to +store log-events there, and have multiple thrift-servers to consume from that. + +* We could use a custom partitioner to send log-events with critical or medium priority to dedicated partitions, for example +to be processed faster and get seen by a human operator-support engineer. diff --git a/clients-simulator/README.md b/clients-simulator/README.md new file mode 100644 index 0000000..ac12de9 --- /dev/null +++ b/clients-simulator/README.md @@ -0,0 +1,13 @@ + + + +### Clients Simulator + +# + +#### Description +* The purpose of this module is to simulate traffic via hitting `thrift-server` with the usage of `thrift-client` library. + + +#### Sample Image +![](clients_simulator.png) diff --git a/clients-simulator/clients_simulator.png b/clients-simulator/clients_simulator.png new file mode 100644 index 0000000..91a3b7b Binary files /dev/null and b/clients-simulator/clients_simulator.png differ diff --git a/clients-simulator/pom.xml b/clients-simulator/pom.xml new file mode 100644 index 0000000..104939e --- /dev/null +++ b/clients-simulator/pom.xml @@ -0,0 +1,86 @@ + + + + pollfish-platform + org.chriniko + 1.0-SNAPSHOT + + 4.0.0 + jar + + clients-simulator + + + UTF-8 + + + + + + org.scala-lang + scala-library + + + + org.scalatest + scalatest_2.13 + test + + + + org.chriniko + thrift-client + 1.0-SNAPSHOT + + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + + + + + + + + org.scala-tools + maven-scala-plugin + + + + org.scalatest + scalatest-maven-plugin + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + com.chriniko.pollfish.clients.simulator.BootstrapClientsSimulator + + + + + + + + + + + \ No newline at end of file diff --git a/clients-simulator/src/main/resources/log4j2.xml b/clients-simulator/src/main/resources/log4j2.xml new file mode 100644 index 0000000..d96fd8f --- /dev/null +++ b/clients-simulator/src/main/resources/log4j2.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/BootstrapClientsSimulator.scala b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/BootstrapClientsSimulator.scala new file mode 100644 index 0000000..547474f --- /dev/null +++ b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/BootstrapClientsSimulator.scala @@ -0,0 +1,46 @@ +package com.chriniko.pollfish.clients.simulator + +import java.util.concurrent.locks.LockSupport + +import com.chriniko.pollfish.clients.simulator.infra.ClientSimulationsCoordinator +import org.apache.logging.log4j.Logger + +import scala.concurrent.duration._ +import scala.concurrent.{Await, Future} +import scala.language.postfixOps + +object BootstrapClientsSimulator { + + private val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + + def main(args: Array[String]): Unit = { + + val coordinator = new ClientSimulationsCoordinator(true) + val always = true + + + // Note: keep in mind which client to use based on the thift-server. + val coordinatorTrafficCreator = () => coordinator.runWithAsyncClient(120) + //val coordinatorTrafficCreator = () => coordinator.runWithSyncClient(1) + + if (!always) { + + val f: Future[Seq[coordinator.FlowResult]] = coordinatorTrafficCreator() + Await.result(f, 25000 millis) + + } else { + while (true) { + val f: Future[Seq[coordinator.FlowResult]] = coordinatorTrafficCreator() + Await.result(f, 25000 millis) + + // Note: pacing. + LockSupport.parkNanos((1 seconds).toNanos) + log.info("\n\n\n\n") + } + } + + + } + + +} diff --git a/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/ClientSimulationsCoordinator.scala b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/ClientSimulationsCoordinator.scala new file mode 100644 index 0000000..9b6d074 --- /dev/null +++ b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/ClientSimulationsCoordinator.scala @@ -0,0 +1,109 @@ +package com.chriniko.pollfish.clients.simulator.infra + +import java.util.concurrent.atomic.AtomicInteger +import java.util.concurrent.{Executors, ThreadFactory} + +import com.chriniko.pollfish.clients.simulator.infra.simulation.{AsyncClientSimulation, ClientSimulation, SyncClientSimulation} +import com.chriniko.pollfish.thrift.client.domain.LoggingEventClientError +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.logging.log4j.Logger + +import scala.concurrent.{ExecutionContext, ExecutionContextExecutorService, Future} +import scala.util.{Failure, Success} + +class ClientSimulationsCoordinator(private val failHard: Boolean) { + + protected val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + + private implicit val mapper: ObjectMapper = new ObjectMapper(); + + private implicit val executionContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService( + Executors.newFixedThreadPool(120, new ThreadFactory { + + val idx = new AtomicInteger() + + override def newThread(runnable: Runnable): Thread = { + val t = new Thread(runnable) + t.setName(s"client-sim-coord-${idx.getAndIncrement()}") + t + } + })) + + // --- + + def runWithSyncClient(clients: Int): Future[Seq[FlowResult]] = { + run(clients, createFlow(new SyncClientSimulation)) + } + + def runWithAsyncClient(clients: Int): Future[Seq[FlowResult]] = { + run(clients, createFlow(new AsyncClientSimulation)) + } + + // --- + + + private def run(clients: Int, flowResult: Future[FlowResult]): Future[Seq[FlowResult]] = { + val fs: Seq[Future[FlowResult]] = (1 to clients).map { _ => registerResultHandler(flowResult) } + val f: Future[Seq[FlowResult]] = Future.sequence(fs) + f + } + + private def createFlow(client: ClientSimulation): Future[FlowResult] = { + + val flow: Future[FlowResult] = for { + res1 <- client.monitorServiceTrafficMaker() + res2 <- client.transactionTrafficMaker() + res3 <- client.userActionTrafficMaker() + } yield { + FlowResult(res1, res2, res3) + } + + flow + } + + private def registerResultHandler(flow: Future[FlowResult])(implicit mapper: ObjectMapper): Future[FlowResult] = { + + flow.onComplete { + case Failure(exception) => + log.error(s"clientFlow failure, message: ${exception.getMessage}", exception) + + case Success(value) => + if (value.anyError) { + log.error(s"clientFlow failure, message: ${value.info}") + if (failHard) System.exit(-1) + + } else { + log.info(s"clientFlow success, message: ${value.info}\n") + } + } + + flow + } + + + // --- infra --- + + type TrafficMakerResult = Either[LoggingEventClientError, LoggingEvent] + + case class FlowResult(monitorResult: TrafficMakerResult, transactionResult: TrafficMakerResult, userActionResult: TrafficMakerResult) { + + def info: String = { + + val sb = new StringBuilder() + + val f: (Any, StringBuilder) => Unit = (x, _sb) => _sb.append(s"\n ${x.toString}") + + monitorResult.fold(f(_, sb), f(_, sb)) + transactionResult.fold(f(_, sb), f(_, sb)) + userActionResult.fold(f(_, sb), f(_, sb)) + + sb.toString() + } + + def anyError: Boolean = { + monitorResult.isLeft || transactionResult.isLeft || userActionResult.isLeft + } + } + +} diff --git a/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/AsyncClientSimulation.scala b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/AsyncClientSimulation.scala new file mode 100644 index 0000000..954234f --- /dev/null +++ b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/AsyncClientSimulation.scala @@ -0,0 +1,57 @@ +package com.chriniko.pollfish.clients.simulator.infra.simulation + +import java.util.concurrent.ThreadLocalRandom + +import com.chriniko.pollfish.thrift.client.LoggingEventServiceAsyncClient +import com.chriniko.pollfish.thrift.client.domain.{HealthStatusResponse, LogEvent, LoggingEventClientError} +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent +import com.fasterxml.jackson.databind.ObjectMapper + +import scala.concurrent.{ExecutionContext, Future} + +class AsyncClientSimulation(implicit val mapper: ObjectMapper, val executionContext: ExecutionContext) extends ClientSimulation { + + + private implicit val clientSupplier: () => LoggingEventServiceAsyncClient = () => new LoggingEventServiceAsyncClient("localhost", 9090, mapper) + + private implicit val pullHealthCheck: () => Future[Either[LoggingEventClientError, HealthStatusResponse]] = () => clientSupplier().healthStatus() + + + // --- + + override def checkStatus(): Future[Unit] = { + pullHealthCheck().map(resp => printCheckStatusResponse(() => resp)) + } + + override def userActionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + val evt = createUserActionEvent() + sendToServer(evt) + } + + override def monitorServiceTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + val evt = createMonitorServiceEvent() + sendToServer(evt) + } + + override def transactionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + val evt = createTransactionEvent() + sendToServer(evt) + } + + + // --- + + private def sendToServer(logEvt: LogEvent)(implicit client: () => LoggingEventServiceAsyncClient): Future[Either[LoggingEventClientError, LoggingEvent]] = { + val addOptionalProperties = ThreadLocalRandom.current().nextInt(0, 2) + if (addOptionalProperties == 1) { + + val toSave = enrichLogEvent(logEvt) + client().save(toSave) + + } else { + client().save(logEvt) + } + } + + override def classType: Class[_] = this.getClass +} diff --git a/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/ClientSimulation.scala b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/ClientSimulation.scala new file mode 100644 index 0000000..fc1d11c --- /dev/null +++ b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/ClientSimulation.scala @@ -0,0 +1,135 @@ +package com.chriniko.pollfish.clients.simulator.infra.simulation + +import java.util.UUID +import java.util.concurrent.ThreadLocalRandom + +import com.chriniko.pollfish.thrift.client.LoggingEventServiceClient +import com.chriniko.pollfish.thrift.client.domain.{ErrorInfo, HealthStatusResponse, LogEvent, LoggingEventClientError} +import com.chriniko.pollfish.thrift.server.protocol._ +import org.apache.logging.log4j.Logger + +import scala.concurrent.Future + +trait ClientSimulation { + + protected val log: Logger = org.apache.logging.log4j.LogManager.getLogger(classType) + + def classType: Class[_] + + def checkStatus(): Future[Unit] + + def userActionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] + + def monitorServiceTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] + + def transactionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] + + + protected def createUserActionEvent(): LogEvent = { + + val userServiceNode = ThreadLocalRandom.current().nextInt(0, 3) + + val userId = UUID.randomUUID().toString + + val userInfoEvent = new UserInfoEvent() + userInfoEvent.setUserId(userId) + + val t: UserInfoEventType = ThreadLocalRandom.current().nextInt(0, 3) match { + case 0 => + val t = new LoggedIn("http://system-login.com") + val r = new UserInfoEventType() + r.setLoggedIn(t) + r + + case 1 => + val t = new LoggedOut(ThreadLocalRandom.current().nextLong(60, 60 * 20)) + val r = new UserInfoEventType() + r.setLoggedOut(t) + r + + case 2 => + val t = new ClickedOnAdvertisement("http://click-url.com", "http://tracker-url.com") + val r = new UserInfoEventType() + r.setClickedOnAdvertisement(t) + r + } + + userInfoEvent.setType(t) + + val payload = new LoggingEventPayload() + payload.setUserInfoEvent(userInfoEvent) + + val logEvt = LogEvent(s"user_service_$userServiceNode", payload) + logEvt + } + + + protected def createMonitorServiceEvent(): LogEvent = { + + val monitorServiceNode = ThreadLocalRandom.current().nextInt(0, 3) + + val serviceId = UUID.randomUUID().toString + + val monitorServiceEvent = new MonitorServiceEvent() + monitorServiceEvent.setServiceId(serviceId) + monitorServiceEvent.setServiceUrl("http://service.com") + + + val monitorServiceReportType: InfoEventType = ThreadLocalRandom.current().nextInt(0, 3) match { + case 0 => InfoEventType.LOW_MEMORY + case 1 => InfoEventType.CPU_IDLE + case 2 => InfoEventType.CPU_HOT + } + + monitorServiceEvent.setType(monitorServiceReportType) + + val payload = new LoggingEventPayload() + payload.setMonitorServiceEvent(monitorServiceEvent) + + val logEvt = LogEvent(s"monitor_service_$monitorServiceNode", payload) + logEvt + } + + + protected def createTransactionEvent(): LogEvent = { + + val walletServiceNode = ThreadLocalRandom.current().nextInt(0, 3) + + val tx = new TransactionEvent(UUID.randomUUID().toString, "1", "2", 6400.0D) + + val payload = new LoggingEventPayload() + payload.setTransactionEvent(tx) + + val logEvt = LogEvent(s"wallet_service_$walletServiceNode", payload) + + logEvt + } + + + protected def printCheckStatusResponse(implicit pull: () => Either[LoggingEventClientError, HealthStatusResponse]): Unit = { + pull() match { + case Left(error) => + val s: Seq[ErrorInfo] = LoggingEventServiceClient.unwrapAndCollectErrors(error) + s.foreach(s => log.info(s"error occurred in health status, message: ${s.msg} -- trace: ${s.trace}")) + + + case Right(success) => + log.info(s"is healthy: ${success.healthy} \n ${success.info}") + } + } + + protected def enrichLogEvent(logEvt: _root_.com.chriniko.pollfish.thrift.client.domain.LogEvent) = { + val priorityToSelect = ThreadLocalRandom.current().nextInt(0, 3) + val priority = priorityToSelect match { + case 0 => LoggingEventPriority.NORMAL + case 1 => LoggingEventPriority.MEDIUM + case 2 => LoggingEventPriority.CRITICAL + } + + val toSave = logEvt.copy( + metadata = Map[String, String]("somekey1" -> "somevalue1", "somekey2" -> "somevalue2", "somekey3" -> "somevalue3"), + priority = priority + ) + toSave + } +} diff --git a/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/SyncClientSimulation.scala b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/SyncClientSimulation.scala new file mode 100644 index 0000000..1d90935 --- /dev/null +++ b/clients-simulator/src/main/scala/com/chriniko/pollfish/clients/simulator/infra/simulation/SyncClientSimulation.scala @@ -0,0 +1,60 @@ +package com.chriniko.pollfish.clients.simulator.infra.simulation + +import java.util.concurrent.ThreadLocalRandom + +import com.chriniko.pollfish.thrift.client.LoggingEventServiceSyncClient +import com.chriniko.pollfish.thrift.client.domain.{HealthStatusResponse, LogEvent, LoggingEventClientError} +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent +import com.fasterxml.jackson.databind.ObjectMapper + +import scala.concurrent.{ExecutionContext, Future} + +class SyncClientSimulation(implicit val mapper: ObjectMapper, val executionContext: ExecutionContext) extends ClientSimulation { + + private implicit val clientSupplier: () => LoggingEventServiceSyncClient = () => new LoggingEventServiceSyncClient("localhost", 9090, mapper) + + private implicit val pullHealthCheck: () => Either[LoggingEventClientError, HealthStatusResponse] = () => clientSupplier().healthStatus().value + + + // --- + + override def checkStatus(): Future[Unit] = Future(printCheckStatusResponse) + + override def userActionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + Future { + val evt = createUserActionEvent() + sendToServer(evt) + } + } + + override def monitorServiceTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + Future { + val evt = createMonitorServiceEvent() + sendToServer(evt) + } + } + + override def transactionTrafficMaker(): Future[Either[LoggingEventClientError, LoggingEvent]] = { + Future { + val evt = createTransactionEvent() + sendToServer(evt) + } + } + + + // --- + + private def sendToServer(logEvt: LogEvent)(implicit client: () => LoggingEventServiceSyncClient): Either[LoggingEventClientError, LoggingEvent] = { + val addOptionalProperties = ThreadLocalRandom.current().nextInt(0, 2) + + if (addOptionalProperties == 1) { + val toSave = enrichLogEvent(logEvt) + client().save(toSave).value + + } else { + client().save(logEvt).value + } + } + + override def classType: Class[_] = this.getClass +} diff --git a/infra/README.md b/infra/README.md new file mode 100644 index 0000000..0110292 --- /dev/null +++ b/infra/README.md @@ -0,0 +1,60 @@ + + +### Infra + +# + +#### Description +* Contains the necessary infrastructure (docker-images) that our platform is using, dependencies: + * Apache Kafka (1 Zookeeper with 3 Kafka Brokers) + * Cassandra (3 nodes) + +#### Prerequisites + +1) Docker installed on your machine + +2) Docker compose installed on your machine + + +#### Running/Setting up Apache Kafka (1 Zookeeper with 3 Kafka Brokers) + +* Setup docker containers for Zookeeper and Kafka: `docker-compose -f docker-compose-kafka-infra.yml up` + +* Enter in some kafka-broker docker container: ` docker exec -it bash` + +* List topics (to make sure it is deleted from `docker volume prune`): `root@kafka1:/bin# kafka-topics --list --zookeeper zookeeper:2181` + +* Create `log-events` topic: `root@kafka1:/bin# kafka-topics --create --zookeeper zookeeper:2181 --replication-factor 3 --partitions 16 --topic log-events` + +* Check if all ok: `root@kafka1:/bin# kafka-topics --bootstrap-server=localhost:9092 --describe --topic log-events` + + * Output: + ```text + Topic: log-events PartitionCount: 16 ReplicationFactor: 3 Configs: + Topic: log-events Partition: 0 Leader: 102 Replicas: 102,1,3 Isr: 102,1,3 Offline: + Topic: log-events Partition: 1 Leader: 1 Replicas: 1,3,102 Isr: 1,3,102 Offline: + Topic: log-events Partition: 2 Leader: 3 Replicas: 3,102,1 Isr: 3,102,1 Offline: + Topic: log-events Partition: 3 Leader: 102 Replicas: 102,3,1 Isr: 102,3,1 Offline: + Topic: log-events Partition: 4 Leader: 1 Replicas: 1,102,3 Isr: 1,102,3 Offline: + Topic: log-events Partition: 5 Leader: 3 Replicas: 3,1,102 Isr: 3,1,102 Offline: + Topic: log-events Partition: 6 Leader: 102 Replicas: 102,1,3 Isr: 102,1,3 Offline: + Topic: log-events Partition: 7 Leader: 1 Replicas: 1,3,102 Isr: 1,3,102 Offline: + Topic: log-events Partition: 8 Leader: 3 Replicas: 3,102,1 Isr: 3,102,1 Offline: + Topic: log-events Partition: 9 Leader: 102 Replicas: 102,3,1 Isr: 102,3,1 Offline: + Topic: log-events Partition: 10 Leader: 1 Replicas: 1,102,3 Isr: 1,102,3 Offline: + Topic: log-events Partition: 11 Leader: 3 Replicas: 3,1,102 Isr: 3,1,102 Offline: + Topic: log-events Partition: 12 Leader: 102 Replicas: 102,1,3 Isr: 102,1,3 Offline: + Topic: log-events Partition: 13 Leader: 1 Replicas: 1,3,102 Isr: 1,3,102 Offline: + Topic: log-events Partition: 14 Leader: 3 Replicas: 3,102,1 Isr: 3,102,1 Offline: + Topic: log-events Partition: 15 Leader: 102 Replicas: 102,3,1 Isr: 102,3,1 Offline: + + ``` + +* Optional, after some time: `docker compose ps` +* Optional, after some time: `docker-compose down` + + + +#### Running up Cassandra (3 nodes) + +* Execute: ` docker-compose -f docker-compose-cassandra-infra.yml up` diff --git a/infra/docker-compose-cassandra-infra.yml b/infra/docker-compose-cassandra-infra.yml new file mode 100644 index 0000000..7f6ea04 --- /dev/null +++ b/infra/docker-compose-cassandra-infra.yml @@ -0,0 +1,21 @@ +version: "3.3" + + +services: + + cassandra: + image: cassandra:3.11.2 + container_name: cassandra + ports: + - "9042:9042" + environment: + - "MAX_HEAP_SIZE=256M" + - "HEAP_NEWSIZE=128M" + restart: always + volumes: + - ./out/cassandra_data:/var/lib/cassandra + healthcheck: + test: [ "CMD", "cqlsh", "-u cassandra", "-p cassandra" ,"-e describe keyspaces" ] + interval: 15s + timeout: 10s + retries: 10 diff --git a/infra/docker-compose-kafka-infra.yml b/infra/docker-compose-kafka-infra.yml new file mode 100644 index 0000000..b6af7bb --- /dev/null +++ b/infra/docker-compose-kafka-infra.yml @@ -0,0 +1,68 @@ +version: "3.3" + + + +services: + zookeeper: + image: confluentinc/cp-zookeeper:5.4.0 + hostname: zookeeper + container_name: zookeeper + ports: + - "2181:2181" + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + + kafka1: + image: confluentinc/cp-server:5.4.0 + hostname: kafka1 + container_name: kafka1 + depends_on: + - zookeeper + ports: + - "19092:19092" + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092,PLAINTEXT_HOST://localhost:19092 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2 + KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 + KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false' + + kafka2: + image: confluentinc/cp-server:5.4.0 + hostname: kafka2 + container_name: kafka2 + depends_on: + - zookeeper + ports: + - "29092:29092" + environment: + KAFKA_BROKER_ID: 102 + KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9092,PLAINTEXT_HOST://localhost:29092 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2 + KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 + KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false' + + kafka3: + image: confluentinc/cp-server:5.4.0 + hostname: kafka3 + container_name: kafka3 + depends_on: + - zookeeper + ports: + - "39092:39092" + environment: + KAFKA_BROKER_ID: 3 + KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9092,PLAINTEXT_HOST://localhost:39092 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2 + KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 + KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false' \ No newline at end of file diff --git a/infra/pom.xml b/infra/pom.xml new file mode 100644 index 0000000..1965f0c --- /dev/null +++ b/infra/pom.xml @@ -0,0 +1,15 @@ + + + + pollfish-platform + org.chriniko + 1.0-SNAPSHOT + + 4.0.0 + + infra + + + \ No newline at end of file diff --git a/kafka-consumer/README.md b/kafka-consumer/README.md new file mode 100644 index 0000000..bbc84b4 --- /dev/null +++ b/kafka-consumer/README.md @@ -0,0 +1,67 @@ + + +### Kafka Consumer (Logging-events-consumer) + +# + + +#### Description +* The purpose of this module is to consume the log-event messages from kafka topics, and materialize them in Cassandra database +based on our query needs. + + +#### Important Notes: + +* Do not remove `--##--` from [cassandra_db_setup.cql](src/main/resources/script/cassandra_db_setup.cql) it is needed from the parser during +initialization of the script, moreover if you want to introduce a new script, add it (`--##--`) before your script. + + +#### Tables supported - queries examples: + + + +```cassandraql + +-- 1 +select * from poll_fish.logging_evts_by_priority_ord_time_desc +where priority = 'NORMAL'; + + +-- 2 +select * from poll_fish.logging_evts_by_priority_ord_time_desc +where priority = 'NORMAL' and time < '2020-11-26T19:25:19.694Z'; + +select * from poll_fish.logging_evts_by_type_ord_time_desc +where type = 'USER_INFO_EVENT' and time < '2020-11-26T19:25:19.694Z'; + + + +-- 3 +select * from poll_fish.logging_evts_by_priority_by_type_ord_time_desc +where priority = 'CRITICAL' and type = 'TRANSACTION_EVENT' and time < '2020-11-30T19:25:19.694Z'; + + + +-- 4 +select * from poll_fish.logging_evts_by_or_by_prio_by_typ_ord_t_desc +where origin = 'wallet_service_0' and priority = 'CRITICAL' and type = 'TRANSACTION_EVENT' and time < '2020-11-30T19:25:19.694Z'; + +select * from poll_fish.logging_evts_by_or_by_prio_by_typ_ord_t_desc +where origin = 'wallet_service_1' and priority = 'CRITICAL' and type = 'TRANSACTION_EVENT' and time < '2020-11-30T19:25:19.694Z'; + +select * from poll_fish.logging_evts_by_or_by_prio_by_typ_ord_t_desc +where origin = 'wallet_service_2' and priority = 'CRITICAL' and type = 'TRANSACTION_EVENT' and time < '2020-11-30T19:25:19.694Z'; + + + +-- 5 +select * from poll_fish.logging_evts_by_or_ord_prio_typ_t_desc +where origin = 'wallet_service_2'; + +select * from poll_fish.logging_evts_by_or_ord_prio_typ_t_desc +where origin = 'wallet_service_2' and priority = 'CRITICAL'; + +``` + +![](kaf_consumer.png) + diff --git a/kafka-consumer/kaf_consumer.png b/kafka-consumer/kaf_consumer.png new file mode 100644 index 0000000..6638e93 Binary files /dev/null and b/kafka-consumer/kaf_consumer.png differ diff --git a/kafka-consumer/pom.xml b/kafka-consumer/pom.xml new file mode 100644 index 0000000..d7ac23d --- /dev/null +++ b/kafka-consumer/pom.xml @@ -0,0 +1,136 @@ + + + + org.chriniko + pollfish-platform + 1.0-SNAPSHOT + + 4.0.0 + jar + + + kafka-consumer + + + UTF-8 + 2.5.31 + 2.13 + + + + + + org.scala-lang + scala-library + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.chriniko + thrift-server + 1.0-SNAPSHOT + + + + + com.typesafe.akka + akka-stream-kafka_${scala.binary.version} + + + com.typesafe.akka + akka-stream_${scala.binary.version} + + + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + + + com.datastax.oss + java-driver-core + + + + com.datastax.oss + java-driver-query-builder + 4.9.0 + + + + + org.scalatest + scalatest_2.13 + test + + + + + + + + + + + + org.scala-tools + maven-scala-plugin + + + + org.scalatest + scalatest-maven-plugin + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + + ${project.build.directory}/libs + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + libs/ + + com.chriniko.pollfish.kafka.consumer.BootstrapKafkaConsumer + + + + + + + + + + + \ No newline at end of file diff --git a/kafka-consumer/src/main/resources/application.conf b/kafka-consumer/src/main/resources/application.conf new file mode 100644 index 0000000..e52160c --- /dev/null +++ b/kafka-consumer/src/main/resources/application.conf @@ -0,0 +1,149 @@ + + +# Properties for akka.kafka.ConsumerSettings can be +# defined in this section or a configuration section with +# the same layout. +akka.kafka.consumer { + # Config path of Akka Discovery method + # "akka.discovery" to use the Akka Discovery method configured for the ActorSystem + discovery-method = akka.discovery + + # Set a service name for use with Akka Discovery + # https://doc.akka.io/docs/alpakka-kafka/current/discovery.html + service-name = "" + + # Timeout for getting a reply from the discovery-method lookup + resolve-timeout = 3 seconds + + # Tuning property of scheduled polls. + # Controls the interval from one scheduled poll to the next. + poll-interval = 50ms + + # Tuning property of the `KafkaConsumer.poll` parameter. + # Note that non-zero value means that the thread that + # is executing the stage will be blocked. See also the `wakup-timeout` setting below. + poll-timeout = 50ms + + # The stage will delay stopping the internal actor to allow processing of + # messages already in the stream (required for successful committing). + # This can be set to 0 for streams using `DrainingControl`. + stop-timeout = 30s + + # Duration to wait for `KafkaConsumer.close` to finish. + close-timeout = 20s + + # If offset commit requests are not completed within this timeout + # the returned Future is completed `CommitTimeoutException`. + # The `Transactional.source` waits this ammount of time for the producer to mark messages as not + # being in flight anymore as well as waiting for messages to drain, when rebalance is triggered. + commit-timeout = 15s + + # If commits take longer than this time a warning is logged + commit-time-warning = 1s + + # Not relevant for Kafka after version 2.1.0. + # If set to a finite duration, the consumer will re-send the last committed offsets periodically + # for all assigned partitions. See https://issues.apache.org/jira/browse/KAFKA-4682. + commit-refresh-interval = infinite + + # Fully qualified config path which holds the dispatcher configuration + # to be used by the KafkaConsumerActor. Some blocking may occur. + use-dispatcher = "akka.kafka.io-blocking-dispatcher" + + # Properties defined by org.apache.kafka.clients.consumer.ConsumerConfig + # can be defined in this configuration section. + kafka-clients { + # Disable auto-commit by default + enable.auto.commit = false + } + + # Time to wait for pending requests when a partition is closed + wait-close-partition = 500ms + + # Limits the query to Kafka for a topic's position + position-timeout = 5s + + # When using `AssignmentOffsetsForTimes` subscriptions: timeout for the + # call to Kafka's API + offset-for-times-timeout = 5s + + # Timeout for akka.kafka.Metadata requests + # This value is used instead of Kafka's default from `default.api.timeout.ms` + # which is 1 minute. + metadata-request-timeout = 5s + + # Interval for checking that transaction was completed before closing the consumer. + # Used in the transactional flow for exactly-once-semantics processing. + eos-draining-check-interval = 30ms + + # Issue warnings when a call to a partition assignment handler method takes + # longer than this. + partition-handler-warning = 5s + + # Settings for checking the connection to the Kafka broker. Connection checking uses `listTopics` requests with the timeout + # configured by `consumer.metadata-request-timeout` + connection-checker { + + #Flag to turn on connection checker + enable = false + + # Amount of attempts to be performed after a first connection failure occurs + # Required, non-negative integer + max-retries = 3 + + # Interval for the connection check. Used as the base for exponential retry. + check-interval = 15s + + + # Check interval multiplier for backoff interval + # Required, positive number + backoff-factor = 2.0 + } + +} + + + + + + +# Properties for akka.kafka.CommitterSettings can be +# defined in this section or a configuration section with +# the same layout. +akka.kafka.committer { + + # Maximum number of messages in a single commit batch + max-batch = 1000 + + # Maximum interval between commits + max-interval = 10s + + # Parallelsim for async committing + parallelism = 100 + + # API may change. + # Delivery of commits to the internal actor + # WaitForAck: Expect replies for commits, and backpressure the stream if replies do not arrive. + # SendAndForget: Send off commits to the internal actor without expecting replies (experimental feature since 1.1) + delivery = WaitForAck + + # API may change. + # Controls when a `Committable` message is queued to be committed. + # OffsetFirstObserved: When the offset of a message has been successfully produced. + # NextOffsetObserved: When the next offset is observed. + when = OffsetFirstObserved +} + + + + +# The dispatcher that will be used by default by consumer and +# producer stages. +akka.kafka.io-blocking-dispatcher { + type = "Dispatcher" + executor = "thread-pool-executor" + + thread-pool-executor { + fixed-pool-size = 96 + } +} diff --git a/kafka-consumer/src/main/resources/log4j2.xml b/kafka-consumer/src/main/resources/log4j2.xml new file mode 100644 index 0000000..8bd349e --- /dev/null +++ b/kafka-consumer/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kafka-consumer/src/main/resources/script/cassandra_db_setup.cql b/kafka-consumer/src/main/resources/script/cassandra_db_setup.cql new file mode 100644 index 0000000..ea330cd --- /dev/null +++ b/kafka-consumer/src/main/resources/script/cassandra_db_setup.cql @@ -0,0 +1,131 @@ +--##-- +CREATE KEYSPACE IF NOT EXISTS poll_fish WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; + +--##-- +USE poll_fish; + + +--##-- +drop table if exists logging_evts_by_type_ord_time_desc; + +--##-- +create table logging_evts_by_type_ord_time_desc +( + + version int, + + id uuid, + origin text, + + time timestamp, + + metadata map, + + type text, + priority text, + + payload text, + + primary key ( type, time ) +) WITH CLUSTERING ORDER BY (time desc); + + +--##-- +drop table if exists logging_evts_by_priority_ord_time_desc; + +--##-- +create table logging_evts_by_priority_ord_time_desc +( + + version int, + + id uuid, + origin text, + + time timestamp, + + metadata map, + + type text, + priority text, + + payload text, + + primary key ( priority, time ) +) WITH CLUSTERING ORDER BY (time desc); + + +--##-- +drop table if exists logging_evts_by_priority_by_type_ord_time_desc; + +--##-- +create table logging_evts_by_priority_by_type_ord_time_desc +( + + version int, + + id uuid, + origin text, + + time timestamp, + + metadata map, + + type text, + priority text, + + payload text, + + primary key ( (priority, type), time ) +) WITH CLUSTERING ORDER BY (time desc); + + +--##-- +drop table if exists logging_evts_by_or_by_prio_by_typ_ord_t_desc; + +--##-- +create table logging_evts_by_or_by_prio_by_typ_ord_t_desc +( + + version int, + + id uuid, + origin text, + + time timestamp, + + metadata map, + + type text, + priority text, + + payload text, + + primary key ( (origin, priority, type), time ) +) WITH CLUSTERING ORDER BY (time desc); + + + +--##-- +drop table if exists logging_evts_by_or_ord_prio_typ_t_desc; + +--##-- +create table logging_evts_by_or_ord_prio_typ_t_desc +( + + version int, + + id uuid, + origin text, + + time timestamp, + + metadata map, + + type text, + priority text, + + payload text, + + primary key ( (origin), priority, type, time ) +) WITH CLUSTERING ORDER BY (priority asc, type asc, time desc); \ No newline at end of file diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/BootstrapKafkaConsumer.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/BootstrapKafkaConsumer.scala new file mode 100644 index 0000000..e25d314 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/BootstrapKafkaConsumer.scala @@ -0,0 +1,45 @@ +package com.chriniko.pollfish.kafka.consumer + +import java.util.UUID + +import akka.Done +import akka.kafka.scaladsl.Consumer +import com.chriniko.pollfish.kafka.consumer.db.CassandraStore +import com.chriniko.pollfish.kafka.consumer.de.LoggingEventDeserializer +import com.chriniko.pollfish.kafka.consumer.infra.LoggingEventsConsumer +import org.apache.logging.log4j.Logger + +import scala.language.postfixOps + +object BootstrapKafkaConsumer { + + private val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + + def main(args: Array[String]): Unit = { + + val cassandraStore = new CassandraStore() + val messageDeserializer = new LoggingEventDeserializer(cassandraStore) + + val kafkaConsumer = new LoggingEventsConsumer(messageDeserializer) + + kafkaConsumer.run("log-events", 16, s"group_${UUID.randomUUID()}", 1) + + val controls: Seq[Consumer.DrainingControl[Done]] = kafkaConsumer.getControls + log.info(s"controls created: ${controls.size}") + + + // Note: if we want to terminate uncomment following section: + /* + + Thread.sleep(15_000) + + val f: Future[(Seq[Done], Terminated)] = kafkaConsumer.stop() + Await.result(f, 25000 millis) + + log.info("finished...") + + */ + + } + +} diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/CassandraStore.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/CassandraStore.scala new file mode 100644 index 0000000..d2d1839 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/CassandraStore.scala @@ -0,0 +1,117 @@ +package com.chriniko.pollfish.kafka.consumer.db + +import java.time.temporal.ChronoUnit +import java.time.{Duration, Instant} +import java.util +import java.util.{Collections, UUID} + +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent +import com.datastax.oss.driver.api.core.CqlSession +import com.datastax.oss.driver.api.core.cql.{BatchableStatement, DefaultBatchType, SimpleStatement, Statement} +import com.datastax.oss.driver.api.querybuilder.QueryBuilder +import com.datastax.oss.driver.api.querybuilder.QueryBuilder._ +import com.datastax.oss.driver.internal.core.cql.DefaultBatchStatement +import org.apache.logging.log4j.Logger + +import scala.collection.mutable.ListBuffer +import scala.io.Source + +class CassandraStore { + + private val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + private val session: CqlSession = CqlSession.builder().build() + + loadScript() + + private def loadScript(): Unit = { + + val acc = ListBuffer[String]() + + def f(): Unit = { + val q = acc.mkString + log.debug(s"will execute query: $q") + session.execute(q) + } + + Source.fromResource("script/cassandra_db_setup.cql").getLines().foreach { line => + if (line == "--##--") { + + if (acc.nonEmpty) { + f() + acc.clear() + } + + } else { + if (line.nonEmpty && line != "--##--") acc += line + } + } + + if (acc.nonEmpty) { + f() + } + + } + + + def store(evt: LoggingEvent): Boolean = { + + val whichType = if (evt.m.isSetMonitorServiceEvent) "MONITOR_SERVICE_EVENT" + else if (evt.m.isSetTransactionEvent) "TRANSACTION_EVENT" + else "USER_INFO_EVENT" + + def _stat(tableName: String) = createStatement(tableName, evt, whichType) + + val statements: Seq[SimpleStatement] = List( + "logging_evts_by_type_ord_time_desc", + "logging_evts_by_priority_ord_time_desc", + "logging_evts_by_priority_by_type_ord_time_desc", + "logging_evts_by_or_by_prio_by_typ_ord_t_desc", + "logging_evts_by_or_ord_prio_typ_t_desc" + ).map(_stat) + + import scala.jdk.CollectionConverters._ + val l = new util.ArrayList[BatchableStatement[_]](statements.asJava) + val batchStatement = constructBatchStatement(l) + + session.execute(batchStatement).wasApplied() + } + + // TODO: IMPORTANT IMPROVE - USE preparedStatement + private def createStatement(tableName: String, evt: LoggingEvent, whichType: String): SimpleStatement = { + QueryBuilder.insertInto(tableName) + .value("version", literal(evt.v)) + .value("id", literal(UUID.fromString(evt.id))) + .value("origin", literal(evt.origin)) + .value("time", literal(Instant.ofEpochMilli(evt.time))) + .value("metadata", literal(evt.metadata)) + .value("type", literal(whichType)) + .value("priority", literal(evt.priority.name())) + .value("payload", literal(evt.toString)) + .build() + } + + private def constructBatchStatement(l: util.ArrayList[BatchableStatement[_]]) = { + new DefaultBatchStatement( + DefaultBatchType.LOGGED, + l, + null, + null, + null, + null, + null, + null, + Collections.emptyMap(), + null, + false, + Statement.NO_DEFAULT_TIMESTAMP, + null, + Integer.MIN_VALUE, + null, + null, + Duration.of(2000, ChronoUnit.MILLIS), + null, + Statement.NO_NOW_IN_SECONDS) + } + + +} diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/LogEventRecord.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/LogEventRecord.scala new file mode 100644 index 0000000..18d7349 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/LogEventRecord.scala @@ -0,0 +1,13 @@ +package com.chriniko.pollfish.kafka.consumer.db + +import java.time.Instant +import java.util.UUID + +case class LogEventRecord(version: Int, + id: UUID, + origin: String, + time: Instant, + metadata: Map[String, String], + `type`: String, + priority: String, + payload: String) diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/cassandra_reminder_notes.txt b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/cassandra_reminder_notes.txt new file mode 100644 index 0000000..55b9c48 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/db/cassandra_reminder_notes.txt @@ -0,0 +1,108 @@ + +======================================================================================================================== +CASSANDRA NOTES ON PARTITION KEY AND CLUSTERING KEY (COMPOSITE == 1st part PARTITION, 2nd part CLUSTERING) +======================================================================================================================== + +The primary key is a general concept to indicate one or more columns used to retrieve data from a Table. + +The primary key may be SIMPLE and even declared inline: + + create table stackoverflow_simple ( + key text PRIMARY KEY, + data text + ); +That means that it is made by a single column. + + +But the primary key can also be COMPOSITE (aka COMPOUND), generated from more columns. + + create table stackoverflow_composite ( + key_part_one text, + key_part_two int, + data text, + PRIMARY KEY(key_part_one, key_part_two) + ); + +In a situation of COMPOSITE primary key, the "first part" of the key +is called PARTITION KEY (in this example key_part_one is the partition key) and the second part of the key +is the CLUSTERING KEY (in this example key_part_two) + +Please note that the both partition and clustering key can be made by more columns, here's how: + + create table stackoverflow_multiple ( + k_part_one text, + k_part_two int, + k_clust_one text, + k_clust_two int, + k_clust_three uuid, + data text, + PRIMARY KEY((k_part_one, k_part_two), k_clust_one, k_clust_two, k_clust_three) + ); + +Behind these names ... + +The Partition Key is responsible for data distribution across your nodes. +The Clustering Key is responsible for data sorting within the partition. +The Primary Key is equivalent to the Partition Key in a single-field-key table (i.e. Simple). + +The Composite/Compound Key is just any multiple-column key + + +Small usage and content examples +SIMPLE KEY: +insert into stackoverflow_simple (key, data) VALUES ('han', 'solo'); +select * from stackoverflow_simple where key='han'; +table content + +key | data +----+------ +han | solo + +COMPOSITE/COMPOUND KEY can retrieve "wide rows" (i.e. you can query by just the partition key, +even if you have clustering keys defined) + +insert into stackoverflow_composite (key_part_one, key_part_two, data) VALUES ('ronaldo', 9, 'football player'); +insert into stackoverflow_composite (key_part_one, key_part_two, data) VALUES ('ronaldo', 10, 'ex-football player'); +select * from stackoverflow_composite where key_part_one = 'ronaldo'; +table content + + key_part_one | key_part_two | data +--------------+--------------+-------------------- + ronaldo | 9 | football player + ronaldo | 10 | ex-football player +But you can query with all key (both partition and clustering) ... + +select * from stackoverflow_composite + where key_part_one = 'ronaldo' and key_part_two = 10; +query output + + key_part_one | key_part_two | data +--------------+--------------+-------------------- + ronaldo | 10 | ex-football player + +Important note: the partition key is the minimum-specifier needed to perform a query using a where clause. +If you have a composite partition key, like the following + + +eg: PRIMARY KEY((col1, col2), col10, col4)) + +You can perform query only by passing at least both col1 and col2, +these are the 2 columns that define the partition key. +The "general" rule to make query is you have to pass at least all partition key columns, +then you can add optionally each clustering key in the order they're set. + + +so the valid queries are (excluding secondary indexes) + +col1 and col2 +col1 and col2 and col10 +col1 and col2 and col10 and col 4 + +Invalid: + + +col1 and col2 and col4 +anything that does not contain both col1 and col2 + + + diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/LoggingEventDeserializer.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/LoggingEventDeserializer.scala new file mode 100644 index 0000000..98d9742 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/LoggingEventDeserializer.scala @@ -0,0 +1,37 @@ +package com.chriniko.pollfish.kafka.consumer.de + +import akka.Done +import com.chriniko.pollfish.kafka.consumer.db.CassandraStore +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent +import org.apache.kafka.common.utils.Bytes +import org.apache.logging.log4j.Logger +import org.apache.thrift.TDeserializer + +import scala.concurrent.{ExecutionContext, Future} + +class LoggingEventDeserializer(val cassandraStore: CassandraStore) extends MessageDeserializer { + + private val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + + private val tDeserializerThreadLocal: ThreadLocal[TDeserializer] = ThreadLocal.withInitial[TDeserializer](() => new TDeserializer()) + + def process(key: String, value: Bytes)(implicit ex: ExecutionContext): Future[Done] = { + Future(extractMessage(value)) + .map { payload => + + log.debug(s">>>> event consumed: ${payload}") + cassandraStore.store(payload) + + Done.done() + } + } + + def extractMessage(value: Bytes): LoggingEvent = { + val deserializer = tDeserializerThreadLocal.get() + val loggingEvent: LoggingEvent = new LoggingEvent() + deserializer.deserialize(loggingEvent, value.get()) + loggingEvent + } + + +} diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/MessageDeserializer.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/MessageDeserializer.scala new file mode 100644 index 0000000..5b823e2 --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/de/MessageDeserializer.scala @@ -0,0 +1,12 @@ +package com.chriniko.pollfish.kafka.consumer.de + +import akka.Done +import org.apache.kafka.common.utils.Bytes + +import scala.concurrent.{ExecutionContext, Future} + +trait MessageDeserializer { + + def process(key: String, value: Bytes)(implicit ex: ExecutionContext): Future[Done] + +} diff --git a/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/infra/LoggingEventsConsumer.scala b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/infra/LoggingEventsConsumer.scala new file mode 100644 index 0000000..421395a --- /dev/null +++ b/kafka-consumer/src/main/scala/com/chriniko/pollfish/kafka/consumer/infra/LoggingEventsConsumer.scala @@ -0,0 +1,106 @@ +package com.chriniko.pollfish.kafka.consumer.infra + +import akka.Done +import akka.actor.{ActorSystem, Terminated} +import akka.kafka.scaladsl.Consumer.DrainingControl +import akka.kafka.scaladsl.{Committer, Consumer} +import akka.kafka.{CommitterSettings, ConsumerSettings, Subscriptions} +import akka.stream.ActorMaterializer +import akka.stream.scaladsl.RunnableGraph +import com.chriniko.pollfish.kafka.consumer.de.MessageDeserializer +import com.typesafe.config.ConfigFactory +import org.apache.kafka.clients.consumer.ConsumerConfig +import org.apache.kafka.common.serialization.{BytesDeserializer, StringDeserializer} +import org.apache.kafka.common.{Metric, MetricName} +import org.apache.logging.log4j.Logger + +import scala.collection.mutable.ListBuffer +import scala.concurrent.duration.Duration +import scala.concurrent.{ExecutionContextExecutor, Future} + +class LoggingEventsConsumer(val messageDeserializer: MessageDeserializer) { + + private val log: Logger = org.apache.logging.log4j.LogManager.getLogger(this.getClass) + + private val config = ConfigFactory.load("application.conf") + + private implicit val system: ActorSystem = ActorSystem("logging-events-consumer", config) + //system.logConfiguration() + + private implicit val dispatcher: ExecutionContextExecutor = system.dispatchers.lookup("akka.kafka.io-blocking-dispatcher") + + private implicit val materializer: ActorMaterializer = ActorMaterializer() + + private implicit val controls: ListBuffer[DrainingControl[Done]] = ListBuffer[DrainingControl[Done]]() + + def getControls: List[DrainingControl[Done]] = { + controls.toList + } + + def run(topic: String, noOfPartitions: Int, groupId: String, noOfFlows: Int): Unit = { + + val flows: Seq[RunnableGraph[DrainingControl[Done]]] = (1 to noOfFlows).map { idx => + + val consumerConfig = config.getConfig("akka.kafka.consumer") + val consumerSettings = + ConsumerSettings(consumerConfig, new StringDeserializer, new BytesDeserializer) + .withGroupId(groupId) + .withClientId(s"${groupId}__clientId${idx}") + .withBootstrapServers("localhost:19092") + .withProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest") + .withProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false") + + val committerConfig = config.getConfig("akka.kafka.committer") + val committerSettings = CommitterSettings(committerConfig) + + /* + Note: The ConsumerSettings stop-timeout delays stopping the Kafka Consumer and the stream, + but when using drainAndShutdown that delay is not required and can be set to zero. + + https://doc.akka.io/docs/alpakka-kafka/current/consumer.html#draining-control + */ + val cSettings = consumerSettings.withStopTimeout(Duration.Zero) + + val subscription = Subscriptions.topics(topic) + + val flow: RunnableGraph[DrainingControl[Done]] = + Consumer + .committableSource(cSettings, subscription) + .mapAsync(noOfPartitions) { msg => + + // Note: business processing logic. + messageDeserializer + .process(msg.record.key(), msg.record.value()) + .map(_ => msg.committableOffset) + + } + .toMat(Committer.sink(committerSettings))(DrainingControl.apply) + + flow + } + + val cs: Seq[DrainingControl[Done]] = flows.map { flow => flow.run() } + controls ++= cs + } + + def stop(): Future[(Seq[Done] /*controls statuses*/ , Terminated /*system status*/ )] = { + val fs: Seq[Future[Done]] = controls.toList.map { control => control.drainAndShutdown() } + val f: Future[Seq[Done]] = Future.sequence(fs) + + for { + r1 <- f + _ = materializer.shutdown() + r2 <- system.terminate() + } yield { + (r1, r2) + } + + } + + def displayMetrics(control: DrainingControl[Done]): Unit = { + val metrics: Future[Map[MetricName, Metric]] = control.metrics + metrics.foreach(map => log.info(s"\n\nmetrics: ${map.mkString("\n")}")) + } + + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c2a34e7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,172 @@ + + + 4.0.0 + + org.chriniko + pollfish-platform + 1.0-SNAPSHOT + pom + + + UTF-8 + 2.13.0 + + 2.5.31 + 2.13 + + + + thrift-client + thrift-server + kafka-consumer + infra + clients-simulator + + + + + + + + + org.apache.thrift + libthrift + 0.13.0 + + + + org.scala-lang + scala-library + ${scala.version} + + + + org.scalatest + scalatest_2.13 + 3.2.2 + test + + + + org.apache.kafka + kafka-clients + 2.6.0 + + + + com.fasterxml.jackson.core + jackson-databind + 2.11.3 + + + + + org.apache.logging.log4j + log4j-api + 2.13.0 + + + org.apache.logging.log4j + log4j-core + 2.13.0 + + + + org.projectlombok + lombok + 1.18.16 + provided + + + + org.apache.commons + commons-configuration2 + 2.7 + + + commons-beanutils + commons-beanutils + 1.9.2 + + + + com.datastax.oss + java-driver-core + 4.9.0 + + + + + + com.typesafe.akka + akka-stream-kafka_${scala.binary.version} + 2.0.5 + + + com.typesafe.akka + akka-stream_${scala.binary.version} + ${akka.version} + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + + + + + + org.scala-tools + maven-scala-plugin + 2.15.2 + + + + compile + testCompile + + + + + + + org.scalatest + scalatest-maven-plugin + 2.0.2 + + + + + test + + test + + + + + + + + + + + + \ No newline at end of file diff --git a/thrift-client/README.md b/thrift-client/README.md new file mode 100644 index 0000000..03213ae --- /dev/null +++ b/thrift-client/README.md @@ -0,0 +1,9 @@ + +### Thrift Client + +# + +#### Description + +* A library which is the boundary in order to communicate with `thrift-client` + diff --git a/thrift-client/pom.xml b/thrift-client/pom.xml new file mode 100644 index 0000000..78a64c5 --- /dev/null +++ b/thrift-client/pom.xml @@ -0,0 +1,61 @@ + + + + org.chriniko + pollfish-platform + 1.0-SNAPSHOT + + 4.0.0 + jar + + thrift-client + + + UTF-8 + + + + + + org.scala-lang + scala-library + + + + org.scalatest + scalatest_2.13 + test + + + + org.chriniko + thrift-server + 1.0-SNAPSHOT + + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + + + org.scala-tools + maven-scala-plugin + + + + org.scalatest + scalatest-maven-plugin + + + + + + \ No newline at end of file diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceAsyncClient.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceAsyncClient.scala new file mode 100644 index 0000000..b769c3d --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceAsyncClient.scala @@ -0,0 +1,73 @@ +package com.chriniko.pollfish.thrift.client + +import com.chriniko.pollfish.thrift.client.domain.LogEvent +import com.chriniko.pollfish.thrift.server.protocol.{LoggingEvent, LoggingEventService, LoggingEventServiceHealthStatus} +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.http.annotation.NotThreadSafe +import org.apache.thrift.async.{AsyncMethodCallback, TAsyncClientManager} +import org.apache.thrift.protocol.TBinaryProtocol +import org.apache.thrift.transport.TNonblockingSocket + +import scala.concurrent.{Future, Promise} + +/** + * Important Note: this async client should be used only if the thrift-server is using: TThreadedSelectorServer.java server flavour. + * + * @param host + * @param port + * @param mapper + */ +@NotThreadSafe +class LoggingEventServiceAsyncClient(val host: String, val port: Int, val mapper: ObjectMapper) extends LoggingEventServiceClient[Future] { + + + val transport = new TNonblockingSocket(host, port) + val clientManager = new TAsyncClientManager + val protocolFactory = new TBinaryProtocol.Factory + + val client = new LoggingEventService.AsyncClient(protocolFactory, clientManager, transport) + + + override def save(log: LogEvent): Future[LogResponse] = { + + val evt = constructLoggingEvent(log, mapper) + + val p = Promise[LogResponse]() + val f = p.future + + client.save(evt, new AsyncMethodCallback[LoggingEvent] { + override def onComplete(response: LoggingEvent): Unit = { + p.success(Right(response)) + } + + override def onError(exception: Exception): Unit = { + p.success(Left(errorMapping(exception))) + } + }) + + f + } + + override def save(data: Seq[LogEvent]): List[Future[LogResponse]] = + data.map(x => save(x)).toList + + override def healthStatus(): Future[HealthResponse] = { + + val p = Promise[HealthResponse]() + val f = p.future + + client.healthStatus(new AsyncMethodCallback[LoggingEventServiceHealthStatus] { + override def onComplete(response: LoggingEventServiceHealthStatus): Unit = { + p.success( + serializer(response.healthy, response.msg, mapper).asEither + ) + } + + override def onError(exception: Exception): Unit = { + p.success(Left(errorMapping(exception))) + } + }) + + f + } +} diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceClient.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceClient.scala new file mode 100644 index 0000000..d5cb91e --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceClient.scala @@ -0,0 +1,99 @@ +package com.chriniko.pollfish.thrift.client + +import java.io.IOException +import java.nio.ByteBuffer +import java.time.Instant +import java.util.UUID + +import com.chriniko.pollfish.thrift.client.domain.LoggingEventClientError.{GeneralCommError, GeneralError, JsonParsingError, NotValidInputError} +import com.chriniko.pollfish.thrift.client.domain.{ErrorInfo, HealthStatusResponse, LogEvent, LoggingEventClientError} +import com.chriniko.pollfish.thrift.server.protocol.{LoggingEvent, LoggingEventPayload, NotValidInputException} +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.thrift.TException + +import scala.annotation.tailrec +import scala.language.higherKinds +import scala.util.{Failure, Success, Try} + +trait LoggingEventServiceClient[F[_]] { + + // type aliases + type LogResponse = Either[LoggingEventClientError, LoggingEvent] + + type HealthResponse = Either[LoggingEventClientError, HealthStatusResponse] + + // contracts + def save(log: LogEvent): F[LogResponse] + + def save(data: Seq[LogEvent]): List[F[LogResponse]] + + def healthStatus(): F[HealthResponse] + + // --- infra/helper --- + + protected def constructLoggingEvent(log: LogEvent, mapper: ObjectMapper): LoggingEvent = { + + val payload: LoggingEventPayload = log.payload + val evt = new LoggingEvent(UUID.randomUUID().toString, log.origin, Instant.now().toEpochMilli, payload) + + evt.priority = log.priority + + import scala.jdk.CollectionConverters._ + evt.metadata = log.metadata.asJava + + evt + } + + protected def serializer(healthy: Boolean, byteBuffer: ByteBuffer, mapper: ObjectMapper): Try[HealthStatusResponse] = { + Try { + HealthStatusResponse(healthy, mapper.readValue[String](byteBuffer.array(), classOf[String])) + } + } + + protected val errorMapping: Throwable => LoggingEventClientError = { + case e: NotValidInputException => NotValidInputError(e) + case e: TException => GeneralCommError(e) + case e: IOException => JsonParsingError(e) + case e: Throwable => GeneralError(e) + } + + + protected implicit class TryOps[L >: LoggingEventClientError, R](r: Try[R]) { + + def asEither: Either[L, R] = r match { + case Success(something) => Right(something) + case Failure(e) => Left(errorMapping(e)) + } + } + +} + + +// --- companion object --- + +object LoggingEventServiceClient { + + case class AsIs[T](t: T) { + def value: T = t + } + + implicit class AsIsOps[T](val t: T) { + def asIs: AsIs[T] = AsIs(t) + } + + def unwrapAndCollectErrors(e: LoggingEventClientError): List[ErrorInfo] = { + + @tailrec + def helper(e: Throwable, acc: List[ErrorInfo]): List[ErrorInfo] = { + if (e != null) { + val errorInfo = ErrorInfo(e.getMessage, e.getStackTrace.mkString("\n")) + helper(e.getCause, acc :+ errorInfo) + } else { + acc + } + } + + helper(e.capturedError, List()) + } + +} diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceSyncClient.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceSyncClient.scala new file mode 100644 index 0000000..cdd9ebe --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/LoggingEventServiceSyncClient.scala @@ -0,0 +1,46 @@ +package com.chriniko.pollfish.thrift.client + +import com.chriniko.pollfish.thrift.client.LoggingEventServiceClient.AsIs +import com.chriniko.pollfish.thrift.client.domain.LogEvent +import com.chriniko.pollfish.thrift.server.protocol._ +import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.http.annotation.NotThreadSafe +import org.apache.thrift.protocol.TBinaryProtocol +import org.apache.thrift.transport.TSocket + +import scala.util.Try + +@NotThreadSafe +class LoggingEventServiceSyncClient(val host: String, val port: Int, val mapper: ObjectMapper) extends LoggingEventServiceClient[AsIs] { + + // --- attributes --- + private val transport = new TSocket(host, port) + transport.open() + + private val protocol = new TBinaryProtocol(transport) + private val client = new LoggingEventService.Client(protocol) + + + // --- methods --- + + import LoggingEventServiceClient._ + + override def save(log: LogEvent): AsIs[LogResponse] = { + Try { + val evt: LoggingEvent = constructLoggingEvent(log, mapper) + client.save(evt) + } + .asEither + .asIs + } + + override def save(data: Seq[LogEvent]): List[AsIs[LogResponse]] = + data.map(rec => save(rec)).toList + + override def healthStatus(): AsIs[HealthResponse] = { + Try(client.healthStatus()).flatMap(x => serializer(x.healthy, x.msg, mapper)).asEither.asIs + } + + +} + diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/ErrorInfo.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/ErrorInfo.scala new file mode 100644 index 0000000..b1562de --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/ErrorInfo.scala @@ -0,0 +1,3 @@ +package com.chriniko.pollfish.thrift.client.domain + +case class ErrorInfo(msg: String, trace: String) diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/HealthStatusResponse.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/HealthStatusResponse.scala new file mode 100644 index 0000000..fdae1b2 --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/HealthStatusResponse.scala @@ -0,0 +1,3 @@ +package com.chriniko.pollfish.thrift.client.domain + +case class HealthStatusResponse(healthy: Boolean, info: String) diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LogEvent.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LogEvent.scala new file mode 100644 index 0000000..09a3051 --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LogEvent.scala @@ -0,0 +1,8 @@ +package com.chriniko.pollfish.thrift.client.domain + +import com.chriniko.pollfish.thrift.server.protocol.{LoggingEventPayload, LoggingEventPriority} + +case class LogEvent(origin: String, + payload: LoggingEventPayload, + metadata: Map[String, String] = Map.empty, + priority: LoggingEventPriority = LoggingEventPriority.NORMAL) diff --git a/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LoggingEventClientError.scala b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LoggingEventClientError.scala new file mode 100644 index 0000000..02930dc --- /dev/null +++ b/thrift-client/src/main/scala/com/chriniko/pollfish/thrift/client/domain/LoggingEventClientError.scala @@ -0,0 +1,23 @@ +package com.chriniko.pollfish.thrift.client.domain + +import java.io.IOException + +import com.chriniko.pollfish.thrift.server.protocol.NotValidInputException +import org.apache.thrift.TException + +// Algebraic Data Type +sealed abstract class LoggingEventClientError extends Product with Serializable { + def capturedError: Throwable +} + +object LoggingEventClientError { + + final case class NotValidInputError(capturedError: NotValidInputException) extends LoggingEventClientError + + final case class GeneralCommError(capturedError: TException) extends LoggingEventClientError + + final case class GeneralError(capturedError: Throwable) extends LoggingEventClientError + + final case class JsonParsingError(capturedError: IOException) extends LoggingEventClientError + +} \ No newline at end of file diff --git a/thrift-server/README.md b/thrift-server/README.md new file mode 100644 index 0000000..c19d5fb --- /dev/null +++ b/thrift-server/README.md @@ -0,0 +1,22 @@ + + + + + +### Thrift Server + +# + + +#### Description + +* Thrift server holds the protocol (thrift files), so if anyone wants to talk to this server, should have it as a dependency in order to have the generated +stubs/files (eg: `thrift-client` which is the de facto library to talk to `thrift-server`) + + +#### Generate java stubs from defined thrift file: +* Execute in the directory: `~/Desktop//thrift-server/src/main/java` the following command: `thrift -r -out . --gen java logging_event_service.thrift` +* So now you should have the generated files + + + diff --git a/thrift-server/pom.xml b/thrift-server/pom.xml new file mode 100644 index 0000000..aee4e66 --- /dev/null +++ b/thrift-server/pom.xml @@ -0,0 +1,97 @@ + + + + org.chriniko + pollfish-platform + 1.0-SNAPSHOT + + 4.0.0 + jar + + + + UTF-8 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + com.chriniko.pollfish.thrift.server.BootstrapServer + + + + + + + + + + + thrift-server + + + + + + org.apache.thrift + libthrift + + + + org.apache.kafka + kafka-clients + + + + org.apache.logging.log4j + log4j-api + + + org.apache.logging.log4j + log4j-core + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.projectlombok + lombok + + + + org.apache.commons + commons-configuration2 + + + commons-beanutils + commons-beanutils + + + + + + \ No newline at end of file diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/BootstrapServer.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/BootstrapServer.java new file mode 100644 index 0000000..78ebb9d --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/BootstrapServer.java @@ -0,0 +1,22 @@ +package com.chriniko.pollfish.thrift.server; + +import com.chriniko.pollfish.thrift.server.infra.LoggingEventServer; +import com.chriniko.pollfish.thrift.server.infra.ServerFlavour; +import lombok.extern.log4j.Log4j2; +import org.apache.thrift.transport.TTransportException; + + +@Log4j2 +public class BootstrapServer { + + public static void main(String[] args) throws TTransportException { + final LoggingEventServer server = new LoggingEventServer(); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + log.info("shutting down..."); + server.stop(); + })); + + server.start(ServerFlavour.THREADED_SELECTOR_SERVER); + } +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/error/LoggingServerErrorCodes.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/error/LoggingServerErrorCodes.java new file mode 100644 index 0000000..f95df6d --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/error/LoggingServerErrorCodes.java @@ -0,0 +1,15 @@ +package com.chriniko.pollfish.thrift.server.error; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum LoggingServerErrorCodes { + + + SERIALIZATION_ERROR(1000); + + + @Getter + private final int code; +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/LoggingEventServer.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/LoggingEventServer.java new file mode 100644 index 0000000..08f93e1 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/LoggingEventServer.java @@ -0,0 +1,204 @@ +package com.chriniko.pollfish.thrift.server.infra; + +import com.chriniko.pollfish.thrift.server.kafka.AdminClientProvider; +import com.chriniko.pollfish.thrift.server.kafka.ProducerProvider; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEventService; +import com.chriniko.pollfish.thrift.server.service.LoggingEventAsyncServiceImpl; +import com.chriniko.pollfish.thrift.server.service.LoggingEventServiceImpl; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.FileBasedConfiguration; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder; +import org.apache.commons.configuration2.builder.fluent.Parameters; +import org.apache.commons.configuration2.ex.ConfigurationException; +import org.apache.kafka.clients.admin.AdminClient; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.common.utils.Bytes; +import org.apache.thrift.server.TServer; +import org.apache.thrift.server.TSimpleServer; +import org.apache.thrift.server.TThreadPoolServer; +import org.apache.thrift.server.TThreadedSelectorServer; +import org.apache.thrift.transport.TNonblockingServerSocket; +import org.apache.thrift.transport.TServerSocket; +import org.apache.thrift.transport.TTransportException; + +import java.lang.management.ManagementFactory; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.LockSupport; + +@Log4j2 +public class LoggingEventServer { + + private TServer server; + + private final String kafkaBrokers; + private final String clientId; + private final String topicName; + private final int port; + private final int poolSize; + + public LoggingEventServer() { + Parameters params = new Parameters(); + FileBasedConfigurationBuilder builder = + new FileBasedConfigurationBuilder(PropertiesConfiguration.class) + .configure(params.properties().setFileName("application.properties")); + try { + Configuration config = builder.getConfiguration(); + + kafkaBrokers = config.getString("kafka-brokers"); + clientId = config.getString("client-id"); + topicName = config.getString("topic-name"); + port = config.getInt("server-port"); + poolSize = config.getInt("io-intensive-pool.size"); + + } catch (ConfigurationException cex) { + throw new IllegalStateException(cex); + } + + } + + public void start(ServerFlavour flavour) throws TTransportException { + + log.info("will use server flavour: {}", flavour); + switch (flavour) { + case SIMPLE: + server = simpleServer(); + break; + case THREADED_SELECTOR_SERVER: + server = threadedSelectorServer(); + break; + case THREAD_POOL: + server = threadPoolServer(); + break; + } + + Thread t = getCheckServerHealthWorker(); + t.setName("server-status-checker"); + t.start(); + + log.info("Starting the server... "); + server.serve(); + } + + public void stop() { + if (server != null && server.isServing()) { + log.info("Stopping the server... "); + + server.stop(); + + log.info("server stopped."); + } + } + + + private LoggingEventService.Processor getProcessor() { + final String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + final Producer producer = ProducerProvider.get(kafkaBrokers, clientId + "_" + jvmName); + final ObjectMapper mapper = new ObjectMapper(); + final AdminClient adminClient = AdminClientProvider.get(kafkaBrokers); + + + final LoggingEventService.Iface service = new LoggingEventServiceImpl(producer, topicName, adminClient, mapper); + return new LoggingEventService.Processor<>(service); + } + + + private LoggingEventService.AsyncProcessor getAsyncProcessor() { + final String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + final Producer producer = ProducerProvider.get(kafkaBrokers, clientId + "_" + jvmName); + final ObjectMapper mapper = new ObjectMapper(); + final AdminClient adminClient = AdminClientProvider.get(kafkaBrokers); + + final LoggingEventService.AsyncIface service = new LoggingEventAsyncServiceImpl(producer, mapper, topicName, adminClient); + return new LoggingEventService.AsyncProcessor<>(service); + } + + + /** + * Important Note: not good option for production-grade environment. + * + * @return + * @throws TTransportException + */ + private TSimpleServer simpleServer() throws TTransportException { + return new TSimpleServer( + new TServer + .Args(new TServerSocket(port)) + .processor(getProcessor()) + ); + } + + + /** + * Important Note: if you choose this server flavour, then you will need to use the `LoggingEventServiceSyncClient.scala` + * from thrift-client module in order to interact with. + * + * @return + * @throws TTransportException + */ + private TThreadPoolServer threadPoolServer() throws TTransportException { + return new TThreadPoolServer( + new TThreadPoolServer.Args(new TServerSocket(port)) + .executorService(ioIntensive()) + .processor(getProcessor()) + ); + } + + + // + + /** + * Important Note: if you choose this server flavour, then you will need to use the `LoggingEventServiceAsyncClient.scala` + * from thrift-client module in order to interact with. + * + * @return + * @throws TTransportException + */ + private TThreadedSelectorServer threadedSelectorServer() throws TTransportException { + return new TThreadedSelectorServer( + new TThreadedSelectorServer.Args(new TNonblockingServerSocket(port)) + .executorService(ioIntensive()) + .selectorThreads(Runtime.getRuntime().availableProcessors() + 1) + .processor(getAsyncProcessor()) + ); + } + + + private ExecutorService ioIntensive() { + return Executors.newFixedThreadPool(poolSize, new ThreadFactory() { + private AtomicInteger idx = new AtomicInteger(); + + @Override + public Thread newThread(Runnable runnable) { + Thread t = new Thread(runnable); + t.setName("log-event-server-worker-" + idx.getAndIncrement()); + return t; + } + }); + } + + private Thread getCheckServerHealthWorker() { + return new Thread(() -> { + boolean serverOk = false; + + while (!serverOk) { + boolean serving = server.isServing(); + if (serving) { + serverOk = true; + log.info("server is up and running"); + } else { + log.info("server is not up and running... will ping again..."); + LockSupport.parkNanos(TimeUnit.NANOSECONDS.convert(1250, TimeUnit.MILLISECONDS)); + } + } + }); + } + + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/ServerFlavour.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/ServerFlavour.java new file mode 100644 index 0000000..fb81a01 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/infra/ServerFlavour.java @@ -0,0 +1,8 @@ +package com.chriniko.pollfish.thrift.server.infra; + +public enum ServerFlavour { + + SIMPLE, + THREAD_POOL, + THREADED_SELECTOR_SERVER +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/AdminClientProvider.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/AdminClientProvider.java new file mode 100644 index 0000000..7001a9d --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/AdminClientProvider.java @@ -0,0 +1,18 @@ +package com.chriniko.pollfish.thrift.server.kafka; + +import java.util.Properties; + +import org.apache.kafka.clients.admin.AdminClient; +import org.apache.kafka.clients.admin.AdminClientConfig; + +public final class AdminClientProvider { + + private AdminClientProvider() { + } + + public static AdminClient get(String bootstrap) { + Properties config = new Properties(); + config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrap); + return AdminClient.create(config); + } +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/ProducerProvider.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/ProducerProvider.java new file mode 100644 index 0000000..45a3cb8 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/kafka/ProducerProvider.java @@ -0,0 +1,56 @@ +package com.chriniko.pollfish.thrift.server.kafka; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.common.serialization.BytesSerializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.apache.kafka.common.utils.Bytes; + +import java.util.Properties; + +public class ProducerProvider { + + + public static Producer get(String bootstrap, String clientId) { + + Properties props = new Properties(); + props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrap); + props.put(ProducerConfig.CLIENT_ID_CONFIG, clientId); + props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, BytesSerializer.class.getName()); + + setupBatchingAndCompression(props); + setupRetriesInFlightTimeout(props); + + return new KafkaProducer<>(props); + } + + private static void setupBatchingAndCompression( + final Properties props) { + // Linger up to 100 ms before sending batch if size not met + props.put(ProducerConfig.LINGER_MS_CONFIG, 115); + + // Batch up to 64K buffer sizes. + props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16_384 * 4); + + // Use Snappy compression for batch compression. + props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "snappy"); + } + + private static void setupRetriesInFlightTimeout(Properties props) { + // Only one in-flight messages per Kafka broker connection + // - max.in.flight.requests.per.connection (default 5) + props.put(ProducerConfig.MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION, 1); // Note: when is 1 we maintain the order in partition level. + + // Set the number of retries - retries + props.put(ProducerConfig.RETRIES_CONFIG, 3); + + // Request timeout - request.timeout.ms + props.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 15_000); + + // Only retry after specified time. + props.put(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, 1_150); + } + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/ClickedOnAdvertisement.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/ClickedOnAdvertisement.java new file mode 100644 index 0000000..c0b0a34 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/ClickedOnAdvertisement.java @@ -0,0 +1,471 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class ClickedOnAdvertisement implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("ClickedOnAdvertisement"); + + private static final org.apache.thrift.protocol.TField CLICK_URL_FIELD_DESC = new org.apache.thrift.protocol.TField("clickUrl", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField CALLBACK_TRACKER_FIELD_DESC = new org.apache.thrift.protocol.TField("callbackTracker", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new ClickedOnAdvertisementStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new ClickedOnAdvertisementTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.lang.String clickUrl; // required + public @org.apache.thrift.annotation.Nullable java.lang.String callbackTracker; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CLICK_URL((short)1, "clickUrl"), + CALLBACK_TRACKER((short)2, "callbackTracker"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CLICK_URL + return CLICK_URL; + case 2: // CALLBACK_TRACKER + return CALLBACK_TRACKER; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CLICK_URL, new org.apache.thrift.meta_data.FieldMetaData("clickUrl", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.CALLBACK_TRACKER, new org.apache.thrift.meta_data.FieldMetaData("callbackTracker", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(ClickedOnAdvertisement.class, metaDataMap); + } + + public ClickedOnAdvertisement() { + } + + public ClickedOnAdvertisement( + java.lang.String clickUrl, + java.lang.String callbackTracker) + { + this(); + this.clickUrl = clickUrl; + this.callbackTracker = callbackTracker; + } + + /** + * Performs a deep copy on other. + */ + public ClickedOnAdvertisement(ClickedOnAdvertisement other) { + if (other.isSetClickUrl()) { + this.clickUrl = other.clickUrl; + } + if (other.isSetCallbackTracker()) { + this.callbackTracker = other.callbackTracker; + } + } + + public ClickedOnAdvertisement deepCopy() { + return new ClickedOnAdvertisement(this); + } + + @Override + public void clear() { + this.clickUrl = null; + this.callbackTracker = null; + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getClickUrl() { + return this.clickUrl; + } + + public ClickedOnAdvertisement setClickUrl(@org.apache.thrift.annotation.Nullable java.lang.String clickUrl) { + this.clickUrl = clickUrl; + return this; + } + + public void unsetClickUrl() { + this.clickUrl = null; + } + + /** Returns true if field clickUrl is set (has been assigned a value) and false otherwise */ + public boolean isSetClickUrl() { + return this.clickUrl != null; + } + + public void setClickUrlIsSet(boolean value) { + if (!value) { + this.clickUrl = null; + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getCallbackTracker() { + return this.callbackTracker; + } + + public ClickedOnAdvertisement setCallbackTracker(@org.apache.thrift.annotation.Nullable java.lang.String callbackTracker) { + this.callbackTracker = callbackTracker; + return this; + } + + public void unsetCallbackTracker() { + this.callbackTracker = null; + } + + /** Returns true if field callbackTracker is set (has been assigned a value) and false otherwise */ + public boolean isSetCallbackTracker() { + return this.callbackTracker != null; + } + + public void setCallbackTrackerIsSet(boolean value) { + if (!value) { + this.callbackTracker = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case CLICK_URL: + if (value == null) { + unsetClickUrl(); + } else { + setClickUrl((java.lang.String)value); + } + break; + + case CALLBACK_TRACKER: + if (value == null) { + unsetCallbackTracker(); + } else { + setCallbackTracker((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case CLICK_URL: + return getClickUrl(); + + case CALLBACK_TRACKER: + return getCallbackTracker(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case CLICK_URL: + return isSetClickUrl(); + case CALLBACK_TRACKER: + return isSetCallbackTracker(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof ClickedOnAdvertisement) + return this.equals((ClickedOnAdvertisement)that); + return false; + } + + public boolean equals(ClickedOnAdvertisement that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_clickUrl = true && this.isSetClickUrl(); + boolean that_present_clickUrl = true && that.isSetClickUrl(); + if (this_present_clickUrl || that_present_clickUrl) { + if (!(this_present_clickUrl && that_present_clickUrl)) + return false; + if (!this.clickUrl.equals(that.clickUrl)) + return false; + } + + boolean this_present_callbackTracker = true && this.isSetCallbackTracker(); + boolean that_present_callbackTracker = true && that.isSetCallbackTracker(); + if (this_present_callbackTracker || that_present_callbackTracker) { + if (!(this_present_callbackTracker && that_present_callbackTracker)) + return false; + if (!this.callbackTracker.equals(that.callbackTracker)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetClickUrl()) ? 131071 : 524287); + if (isSetClickUrl()) + hashCode = hashCode * 8191 + clickUrl.hashCode(); + + hashCode = hashCode * 8191 + ((isSetCallbackTracker()) ? 131071 : 524287); + if (isSetCallbackTracker()) + hashCode = hashCode * 8191 + callbackTracker.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(ClickedOnAdvertisement other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetClickUrl()).compareTo(other.isSetClickUrl()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetClickUrl()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.clickUrl, other.clickUrl); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetCallbackTracker()).compareTo(other.isSetCallbackTracker()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCallbackTracker()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.callbackTracker, other.callbackTracker); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("ClickedOnAdvertisement("); + boolean first = true; + + sb.append("clickUrl:"); + if (this.clickUrl == null) { + sb.append("null"); + } else { + sb.append(this.clickUrl); + } + first = false; + if (!first) sb.append(", "); + sb.append("callbackTracker:"); + if (this.callbackTracker == null) { + sb.append("null"); + } else { + sb.append(this.callbackTracker); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (clickUrl == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'clickUrl' was not present! Struct: " + toString()); + } + if (callbackTracker == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'callbackTracker' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ClickedOnAdvertisementStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ClickedOnAdvertisementStandardScheme getScheme() { + return new ClickedOnAdvertisementStandardScheme(); + } + } + + private static class ClickedOnAdvertisementStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, ClickedOnAdvertisement struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CLICK_URL + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.clickUrl = iprot.readString(); + struct.setClickUrlIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // CALLBACK_TRACKER + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.callbackTracker = iprot.readString(); + struct.setCallbackTrackerIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, ClickedOnAdvertisement struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.clickUrl != null) { + oprot.writeFieldBegin(CLICK_URL_FIELD_DESC); + oprot.writeString(struct.clickUrl); + oprot.writeFieldEnd(); + } + if (struct.callbackTracker != null) { + oprot.writeFieldBegin(CALLBACK_TRACKER_FIELD_DESC); + oprot.writeString(struct.callbackTracker); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ClickedOnAdvertisementTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public ClickedOnAdvertisementTupleScheme getScheme() { + return new ClickedOnAdvertisementTupleScheme(); + } + } + + private static class ClickedOnAdvertisementTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, ClickedOnAdvertisement struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.clickUrl); + oprot.writeString(struct.callbackTracker); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, ClickedOnAdvertisement struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.clickUrl = iprot.readString(); + struct.setClickUrlIsSet(true); + struct.callbackTracker = iprot.readString(); + struct.setCallbackTrackerIsSet(true); + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/InfoEventType.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/InfoEventType.java new file mode 100644 index 0000000..460187a --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/InfoEventType.java @@ -0,0 +1,46 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + + +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public enum InfoEventType implements org.apache.thrift.TEnum { + LOW_MEMORY(0), + CPU_IDLE(1), + CPU_HOT(2); + + private final int value; + + private InfoEventType(int value) { + this.value = value; + } + + /** + * Get the integer value of this enum value, as defined in the Thrift IDL. + */ + public int getValue() { + return value; + } + + /** + * Find a the enum type by its integer value, as defined in the Thrift IDL. + * @return null if the value is not found. + */ + @org.apache.thrift.annotation.Nullable + public static InfoEventType findByValue(int value) { + switch (value) { + case 0: + return LOW_MEMORY; + case 1: + return CPU_IDLE; + case 2: + return CPU_HOT; + default: + return null; + } + } +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedIn.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedIn.java new file mode 100644 index 0000000..0721d07 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedIn.java @@ -0,0 +1,370 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggedIn implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("LoggedIn"); + + private static final org.apache.thrift.protocol.TField URL_FIELD_DESC = new org.apache.thrift.protocol.TField("url", org.apache.thrift.protocol.TType.STRING, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new LoggedInStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new LoggedInTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.lang.String url; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + URL((short)1, "url"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // URL + return URL; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.URL, new org.apache.thrift.meta_data.FieldMetaData("url", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(LoggedIn.class, metaDataMap); + } + + public LoggedIn() { + } + + public LoggedIn( + java.lang.String url) + { + this(); + this.url = url; + } + + /** + * Performs a deep copy on other. + */ + public LoggedIn(LoggedIn other) { + if (other.isSetUrl()) { + this.url = other.url; + } + } + + public LoggedIn deepCopy() { + return new LoggedIn(this); + } + + @Override + public void clear() { + this.url = null; + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getUrl() { + return this.url; + } + + public LoggedIn setUrl(@org.apache.thrift.annotation.Nullable java.lang.String url) { + this.url = url; + return this; + } + + public void unsetUrl() { + this.url = null; + } + + /** Returns true if field url is set (has been assigned a value) and false otherwise */ + public boolean isSetUrl() { + return this.url != null; + } + + public void setUrlIsSet(boolean value) { + if (!value) { + this.url = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case URL: + if (value == null) { + unsetUrl(); + } else { + setUrl((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case URL: + return getUrl(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case URL: + return isSetUrl(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof LoggedIn) + return this.equals((LoggedIn)that); + return false; + } + + public boolean equals(LoggedIn that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_url = true && this.isSetUrl(); + boolean that_present_url = true && that.isSetUrl(); + if (this_present_url || that_present_url) { + if (!(this_present_url && that_present_url)) + return false; + if (!this.url.equals(that.url)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetUrl()) ? 131071 : 524287); + if (isSetUrl()) + hashCode = hashCode * 8191 + url.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(LoggedIn other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetUrl()).compareTo(other.isSetUrl()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetUrl()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.url, other.url); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("LoggedIn("); + boolean first = true; + + sb.append("url:"); + if (this.url == null) { + sb.append("null"); + } else { + sb.append(this.url); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (url == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'url' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class LoggedInStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggedInStandardScheme getScheme() { + return new LoggedInStandardScheme(); + } + } + + private static class LoggedInStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, LoggedIn struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // URL + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.url = iprot.readString(); + struct.setUrlIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, LoggedIn struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.url != null) { + oprot.writeFieldBegin(URL_FIELD_DESC); + oprot.writeString(struct.url); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class LoggedInTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggedInTupleScheme getScheme() { + return new LoggedInTupleScheme(); + } + } + + private static class LoggedInTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, LoggedIn struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.url); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, LoggedIn struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.url = iprot.readString(); + struct.setUrlIsSet(true); + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedOut.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedOut.java new file mode 100644 index 0000000..4913786 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggedOut.java @@ -0,0 +1,366 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggedOut implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("LoggedOut"); + + private static final org.apache.thrift.protocol.TField DURATION_OF_LOGIN_IN_SECS_FIELD_DESC = new org.apache.thrift.protocol.TField("durationOfLoginInSecs", org.apache.thrift.protocol.TType.I64, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new LoggedOutStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new LoggedOutTupleSchemeFactory(); + + public long durationOfLoginInSecs; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + DURATION_OF_LOGIN_IN_SECS((short)1, "durationOfLoginInSecs"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // DURATION_OF_LOGIN_IN_SECS + return DURATION_OF_LOGIN_IN_SECS; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __DURATIONOFLOGININSECS_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.DURATION_OF_LOGIN_IN_SECS, new org.apache.thrift.meta_data.FieldMetaData("durationOfLoginInSecs", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(LoggedOut.class, metaDataMap); + } + + public LoggedOut() { + } + + public LoggedOut( + long durationOfLoginInSecs) + { + this(); + this.durationOfLoginInSecs = durationOfLoginInSecs; + setDurationOfLoginInSecsIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public LoggedOut(LoggedOut other) { + __isset_bitfield = other.__isset_bitfield; + this.durationOfLoginInSecs = other.durationOfLoginInSecs; + } + + public LoggedOut deepCopy() { + return new LoggedOut(this); + } + + @Override + public void clear() { + setDurationOfLoginInSecsIsSet(false); + this.durationOfLoginInSecs = 0; + } + + public long getDurationOfLoginInSecs() { + return this.durationOfLoginInSecs; + } + + public LoggedOut setDurationOfLoginInSecs(long durationOfLoginInSecs) { + this.durationOfLoginInSecs = durationOfLoginInSecs; + setDurationOfLoginInSecsIsSet(true); + return this; + } + + public void unsetDurationOfLoginInSecs() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __DURATIONOFLOGININSECS_ISSET_ID); + } + + /** Returns true if field durationOfLoginInSecs is set (has been assigned a value) and false otherwise */ + public boolean isSetDurationOfLoginInSecs() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __DURATIONOFLOGININSECS_ISSET_ID); + } + + public void setDurationOfLoginInSecsIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __DURATIONOFLOGININSECS_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case DURATION_OF_LOGIN_IN_SECS: + if (value == null) { + unsetDurationOfLoginInSecs(); + } else { + setDurationOfLoginInSecs((java.lang.Long)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case DURATION_OF_LOGIN_IN_SECS: + return getDurationOfLoginInSecs(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case DURATION_OF_LOGIN_IN_SECS: + return isSetDurationOfLoginInSecs(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof LoggedOut) + return this.equals((LoggedOut)that); + return false; + } + + public boolean equals(LoggedOut that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_durationOfLoginInSecs = true; + boolean that_present_durationOfLoginInSecs = true; + if (this_present_durationOfLoginInSecs || that_present_durationOfLoginInSecs) { + if (!(this_present_durationOfLoginInSecs && that_present_durationOfLoginInSecs)) + return false; + if (this.durationOfLoginInSecs != that.durationOfLoginInSecs) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(durationOfLoginInSecs); + + return hashCode; + } + + @Override + public int compareTo(LoggedOut other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetDurationOfLoginInSecs()).compareTo(other.isSetDurationOfLoginInSecs()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDurationOfLoginInSecs()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.durationOfLoginInSecs, other.durationOfLoginInSecs); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("LoggedOut("); + boolean first = true; + + sb.append("durationOfLoginInSecs:"); + sb.append(this.durationOfLoginInSecs); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // alas, we cannot check 'durationOfLoginInSecs' because it's a primitive and you chose the non-beans generator. + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class LoggedOutStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggedOutStandardScheme getScheme() { + return new LoggedOutStandardScheme(); + } + } + + private static class LoggedOutStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, LoggedOut struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // DURATION_OF_LOGIN_IN_SECS + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.durationOfLoginInSecs = iprot.readI64(); + struct.setDurationOfLoginInSecsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + if (!struct.isSetDurationOfLoginInSecs()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'durationOfLoginInSecs' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, LoggedOut struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(DURATION_OF_LOGIN_IN_SECS_FIELD_DESC); + oprot.writeI64(struct.durationOfLoginInSecs); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class LoggedOutTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggedOutTupleScheme getScheme() { + return new LoggedOutTupleScheme(); + } + } + + private static class LoggedOutTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, LoggedOut struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeI64(struct.durationOfLoginInSecs); + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, LoggedOut struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.durationOfLoginInSecs = iprot.readI64(); + struct.setDurationOfLoginInSecsIsSet(true); + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEvent.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEvent.java new file mode 100644 index 0000000..62f4f63 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEvent.java @@ -0,0 +1,1061 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggingEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("LoggingEvent"); + + private static final org.apache.thrift.protocol.TField V_FIELD_DESC = new org.apache.thrift.protocol.TField("v", org.apache.thrift.protocol.TType.I16, (short)1); + private static final org.apache.thrift.protocol.TField ID_FIELD_DESC = new org.apache.thrift.protocol.TField("id", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField ORIGIN_FIELD_DESC = new org.apache.thrift.protocol.TField("origin", org.apache.thrift.protocol.TType.STRING, (short)3); + private static final org.apache.thrift.protocol.TField TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("time", org.apache.thrift.protocol.TType.I64, (short)4); + private static final org.apache.thrift.protocol.TField METADATA_FIELD_DESC = new org.apache.thrift.protocol.TField("metadata", org.apache.thrift.protocol.TType.MAP, (short)5); + private static final org.apache.thrift.protocol.TField M_FIELD_DESC = new org.apache.thrift.protocol.TField("m", org.apache.thrift.protocol.TType.STRUCT, (short)6); + private static final org.apache.thrift.protocol.TField PRIORITY_FIELD_DESC = new org.apache.thrift.protocol.TField("priority", org.apache.thrift.protocol.TType.I32, (short)7); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new LoggingEventStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new LoggingEventTupleSchemeFactory(); + + public short v; // optional + public @org.apache.thrift.annotation.Nullable java.lang.String id; // required + public @org.apache.thrift.annotation.Nullable java.lang.String origin; // required + public long time; // required + public @org.apache.thrift.annotation.Nullable java.util.Map metadata; // optional + public @org.apache.thrift.annotation.Nullable LoggingEventPayload m; // required + /** + * + * @see LoggingEventPriority + */ + public @org.apache.thrift.annotation.Nullable LoggingEventPriority priority; // optional + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + V((short)1, "v"), + ID((short)2, "id"), + ORIGIN((short)3, "origin"), + TIME((short)4, "time"), + METADATA((short)5, "metadata"), + M((short)6, "m"), + /** + * + * @see LoggingEventPriority + */ + PRIORITY((short)7, "priority"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // V + return V; + case 2: // ID + return ID; + case 3: // ORIGIN + return ORIGIN; + case 4: // TIME + return TIME; + case 5: // METADATA + return METADATA; + case 6: // M + return M; + case 7: // PRIORITY + return PRIORITY; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __V_ISSET_ID = 0; + private static final int __TIME_ISSET_ID = 1; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.V,_Fields.METADATA,_Fields.PRIORITY}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.V, new org.apache.thrift.meta_data.FieldMetaData("v", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); + tmpMap.put(_Fields.ID, new org.apache.thrift.meta_data.FieldMetaData("id", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.ORIGIN, new org.apache.thrift.meta_data.FieldMetaData("origin", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.TIME, new org.apache.thrift.meta_data.FieldMetaData("time", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.METADATA, new org.apache.thrift.meta_data.FieldMetaData("metadata", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.MapMetaData(org.apache.thrift.protocol.TType.MAP, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING), + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + tmpMap.put(_Fields.M, new org.apache.thrift.meta_data.FieldMetaData("m", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEventPayload.class))); + tmpMap.put(_Fields.PRIORITY, new org.apache.thrift.meta_data.FieldMetaData("priority", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, LoggingEventPriority.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(LoggingEvent.class, metaDataMap); + } + + public LoggingEvent() { + this.v = (short)1; + + this.priority = com.chriniko.pollfish.thrift.server.protocol.LoggingEventPriority.NORMAL; + + } + + public LoggingEvent( + java.lang.String id, + java.lang.String origin, + long time, + LoggingEventPayload m) + { + this(); + this.id = id; + this.origin = origin; + this.time = time; + setTimeIsSet(true); + this.m = m; + } + + /** + * Performs a deep copy on other. + */ + public LoggingEvent(LoggingEvent other) { + __isset_bitfield = other.__isset_bitfield; + this.v = other.v; + if (other.isSetId()) { + this.id = other.id; + } + if (other.isSetOrigin()) { + this.origin = other.origin; + } + this.time = other.time; + if (other.isSetMetadata()) { + java.util.Map __this__metadata = new java.util.HashMap(other.metadata); + this.metadata = __this__metadata; + } + if (other.isSetM()) { + this.m = new LoggingEventPayload(other.m); + } + if (other.isSetPriority()) { + this.priority = other.priority; + } + } + + public LoggingEvent deepCopy() { + return new LoggingEvent(this); + } + + @Override + public void clear() { + this.v = (short)1; + + this.id = null; + this.origin = null; + setTimeIsSet(false); + this.time = 0; + this.metadata = null; + this.m = null; + this.priority = com.chriniko.pollfish.thrift.server.protocol.LoggingEventPriority.NORMAL; + + } + + public short getV() { + return this.v; + } + + public LoggingEvent setV(short v) { + this.v = v; + setVIsSet(true); + return this; + } + + public void unsetV() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __V_ISSET_ID); + } + + /** Returns true if field v is set (has been assigned a value) and false otherwise */ + public boolean isSetV() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __V_ISSET_ID); + } + + public void setVIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __V_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getId() { + return this.id; + } + + public LoggingEvent setId(@org.apache.thrift.annotation.Nullable java.lang.String id) { + this.id = id; + return this; + } + + public void unsetId() { + this.id = null; + } + + /** Returns true if field id is set (has been assigned a value) and false otherwise */ + public boolean isSetId() { + return this.id != null; + } + + public void setIdIsSet(boolean value) { + if (!value) { + this.id = null; + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getOrigin() { + return this.origin; + } + + public LoggingEvent setOrigin(@org.apache.thrift.annotation.Nullable java.lang.String origin) { + this.origin = origin; + return this; + } + + public void unsetOrigin() { + this.origin = null; + } + + /** Returns true if field origin is set (has been assigned a value) and false otherwise */ + public boolean isSetOrigin() { + return this.origin != null; + } + + public void setOriginIsSet(boolean value) { + if (!value) { + this.origin = null; + } + } + + public long getTime() { + return this.time; + } + + public LoggingEvent setTime(long time) { + this.time = time; + setTimeIsSet(true); + return this; + } + + public void unsetTime() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __TIME_ISSET_ID); + } + + /** Returns true if field time is set (has been assigned a value) and false otherwise */ + public boolean isSetTime() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __TIME_ISSET_ID); + } + + public void setTimeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __TIME_ISSET_ID, value); + } + + public int getMetadataSize() { + return (this.metadata == null) ? 0 : this.metadata.size(); + } + + public void putToMetadata(java.lang.String key, java.lang.String val) { + if (this.metadata == null) { + this.metadata = new java.util.HashMap(); + } + this.metadata.put(key, val); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Map getMetadata() { + return this.metadata; + } + + public LoggingEvent setMetadata(@org.apache.thrift.annotation.Nullable java.util.Map metadata) { + this.metadata = metadata; + return this; + } + + public void unsetMetadata() { + this.metadata = null; + } + + /** Returns true if field metadata is set (has been assigned a value) and false otherwise */ + public boolean isSetMetadata() { + return this.metadata != null; + } + + public void setMetadataIsSet(boolean value) { + if (!value) { + this.metadata = null; + } + } + + @org.apache.thrift.annotation.Nullable + public LoggingEventPayload getM() { + return this.m; + } + + public LoggingEvent setM(@org.apache.thrift.annotation.Nullable LoggingEventPayload m) { + this.m = m; + return this; + } + + public void unsetM() { + this.m = null; + } + + /** Returns true if field m is set (has been assigned a value) and false otherwise */ + public boolean isSetM() { + return this.m != null; + } + + public void setMIsSet(boolean value) { + if (!value) { + this.m = null; + } + } + + /** + * + * @see LoggingEventPriority + */ + @org.apache.thrift.annotation.Nullable + public LoggingEventPriority getPriority() { + return this.priority; + } + + /** + * + * @see LoggingEventPriority + */ + public LoggingEvent setPriority(@org.apache.thrift.annotation.Nullable LoggingEventPriority priority) { + this.priority = priority; + return this; + } + + public void unsetPriority() { + this.priority = null; + } + + /** Returns true if field priority is set (has been assigned a value) and false otherwise */ + public boolean isSetPriority() { + return this.priority != null; + } + + public void setPriorityIsSet(boolean value) { + if (!value) { + this.priority = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case V: + if (value == null) { + unsetV(); + } else { + setV((java.lang.Short)value); + } + break; + + case ID: + if (value == null) { + unsetId(); + } else { + setId((java.lang.String)value); + } + break; + + case ORIGIN: + if (value == null) { + unsetOrigin(); + } else { + setOrigin((java.lang.String)value); + } + break; + + case TIME: + if (value == null) { + unsetTime(); + } else { + setTime((java.lang.Long)value); + } + break; + + case METADATA: + if (value == null) { + unsetMetadata(); + } else { + setMetadata((java.util.Map)value); + } + break; + + case M: + if (value == null) { + unsetM(); + } else { + setM((LoggingEventPayload)value); + } + break; + + case PRIORITY: + if (value == null) { + unsetPriority(); + } else { + setPriority((LoggingEventPriority)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case V: + return getV(); + + case ID: + return getId(); + + case ORIGIN: + return getOrigin(); + + case TIME: + return getTime(); + + case METADATA: + return getMetadata(); + + case M: + return getM(); + + case PRIORITY: + return getPriority(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case V: + return isSetV(); + case ID: + return isSetId(); + case ORIGIN: + return isSetOrigin(); + case TIME: + return isSetTime(); + case METADATA: + return isSetMetadata(); + case M: + return isSetM(); + case PRIORITY: + return isSetPriority(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof LoggingEvent) + return this.equals((LoggingEvent)that); + return false; + } + + public boolean equals(LoggingEvent that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_v = true && this.isSetV(); + boolean that_present_v = true && that.isSetV(); + if (this_present_v || that_present_v) { + if (!(this_present_v && that_present_v)) + return false; + if (this.v != that.v) + return false; + } + + boolean this_present_id = true && this.isSetId(); + boolean that_present_id = true && that.isSetId(); + if (this_present_id || that_present_id) { + if (!(this_present_id && that_present_id)) + return false; + if (!this.id.equals(that.id)) + return false; + } + + boolean this_present_origin = true && this.isSetOrigin(); + boolean that_present_origin = true && that.isSetOrigin(); + if (this_present_origin || that_present_origin) { + if (!(this_present_origin && that_present_origin)) + return false; + if (!this.origin.equals(that.origin)) + return false; + } + + boolean this_present_time = true; + boolean that_present_time = true; + if (this_present_time || that_present_time) { + if (!(this_present_time && that_present_time)) + return false; + if (this.time != that.time) + return false; + } + + boolean this_present_metadata = true && this.isSetMetadata(); + boolean that_present_metadata = true && that.isSetMetadata(); + if (this_present_metadata || that_present_metadata) { + if (!(this_present_metadata && that_present_metadata)) + return false; + if (!this.metadata.equals(that.metadata)) + return false; + } + + boolean this_present_m = true && this.isSetM(); + boolean that_present_m = true && that.isSetM(); + if (this_present_m || that_present_m) { + if (!(this_present_m && that_present_m)) + return false; + if (!this.m.equals(that.m)) + return false; + } + + boolean this_present_priority = true && this.isSetPriority(); + boolean that_present_priority = true && that.isSetPriority(); + if (this_present_priority || that_present_priority) { + if (!(this_present_priority && that_present_priority)) + return false; + if (!this.priority.equals(that.priority)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetV()) ? 131071 : 524287); + if (isSetV()) + hashCode = hashCode * 8191 + v; + + hashCode = hashCode * 8191 + ((isSetId()) ? 131071 : 524287); + if (isSetId()) + hashCode = hashCode * 8191 + id.hashCode(); + + hashCode = hashCode * 8191 + ((isSetOrigin()) ? 131071 : 524287); + if (isSetOrigin()) + hashCode = hashCode * 8191 + origin.hashCode(); + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(time); + + hashCode = hashCode * 8191 + ((isSetMetadata()) ? 131071 : 524287); + if (isSetMetadata()) + hashCode = hashCode * 8191 + metadata.hashCode(); + + hashCode = hashCode * 8191 + ((isSetM()) ? 131071 : 524287); + if (isSetM()) + hashCode = hashCode * 8191 + m.hashCode(); + + hashCode = hashCode * 8191 + ((isSetPriority()) ? 131071 : 524287); + if (isSetPriority()) + hashCode = hashCode * 8191 + priority.getValue(); + + return hashCode; + } + + @Override + public int compareTo(LoggingEvent other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetV()).compareTo(other.isSetV()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetV()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.v, other.v); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetId()).compareTo(other.isSetId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.id, other.id); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetOrigin()).compareTo(other.isSetOrigin()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetOrigin()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.origin, other.origin); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetTime()).compareTo(other.isSetTime()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTime()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.time, other.time); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetMetadata()).compareTo(other.isSetMetadata()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMetadata()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.metadata, other.metadata); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetM()).compareTo(other.isSetM()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetM()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.m, other.m); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetPriority()).compareTo(other.isSetPriority()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetPriority()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.priority, other.priority); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("LoggingEvent("); + boolean first = true; + + if (isSetV()) { + sb.append("v:"); + sb.append(this.v); + first = false; + } + if (!first) sb.append(", "); + sb.append("id:"); + if (this.id == null) { + sb.append("null"); + } else { + sb.append(this.id); + } + first = false; + if (!first) sb.append(", "); + sb.append("origin:"); + if (this.origin == null) { + sb.append("null"); + } else { + sb.append(this.origin); + } + first = false; + if (!first) sb.append(", "); + sb.append("time:"); + sb.append(this.time); + first = false; + if (isSetMetadata()) { + if (!first) sb.append(", "); + sb.append("metadata:"); + if (this.metadata == null) { + sb.append("null"); + } else { + sb.append(this.metadata); + } + first = false; + } + if (!first) sb.append(", "); + sb.append("m:"); + if (this.m == null) { + sb.append("null"); + } else { + sb.append(this.m); + } + first = false; + if (isSetPriority()) { + if (!first) sb.append(", "); + sb.append("priority:"); + if (this.priority == null) { + sb.append("null"); + } else { + sb.append(this.priority); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (id == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'id' was not present! Struct: " + toString()); + } + if (origin == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'origin' was not present! Struct: " + toString()); + } + // alas, we cannot check 'time' because it's a primitive and you chose the non-beans generator. + if (m == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'm' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class LoggingEventStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggingEventStandardScheme getScheme() { + return new LoggingEventStandardScheme(); + } + } + + private static class LoggingEventStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, LoggingEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // V + if (schemeField.type == org.apache.thrift.protocol.TType.I16) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.id = iprot.readString(); + struct.setIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // ORIGIN + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.origin = iprot.readString(); + struct.setOriginIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 4: // TIME + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.time = iprot.readI64(); + struct.setTimeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 5: // METADATA + if (schemeField.type == org.apache.thrift.protocol.TType.MAP) { + { + org.apache.thrift.protocol.TMap _map0 = iprot.readMapBegin(); + struct.metadata = new java.util.HashMap(2*_map0.size); + @org.apache.thrift.annotation.Nullable java.lang.String _key1; + @org.apache.thrift.annotation.Nullable java.lang.String _val2; + for (int _i3 = 0; _i3 < _map0.size; ++_i3) + { + _key1 = iprot.readString(); + _val2 = iprot.readString(); + struct.metadata.put(_key1, _val2); + } + iprot.readMapEnd(); + } + struct.setMetadataIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 6: // M + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.m = new LoggingEventPayload(); + struct.m.read(iprot); + struct.setMIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 7: // PRIORITY + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.priority = com.chriniko.pollfish.thrift.server.protocol.LoggingEventPriority.findByValue(iprot.readI32()); + struct.setPriorityIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + if (!struct.isSetTime()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'time' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, LoggingEvent struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetV()) { + oprot.writeFieldBegin(V_FIELD_DESC); + oprot.writeI16(struct.v); + oprot.writeFieldEnd(); + } + if (struct.id != null) { + oprot.writeFieldBegin(ID_FIELD_DESC); + oprot.writeString(struct.id); + oprot.writeFieldEnd(); + } + if (struct.origin != null) { + oprot.writeFieldBegin(ORIGIN_FIELD_DESC); + oprot.writeString(struct.origin); + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(TIME_FIELD_DESC); + oprot.writeI64(struct.time); + oprot.writeFieldEnd(); + if (struct.metadata != null) { + if (struct.isSetMetadata()) { + oprot.writeFieldBegin(METADATA_FIELD_DESC); + { + oprot.writeMapBegin(new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, struct.metadata.size())); + for (java.util.Map.Entry _iter4 : struct.metadata.entrySet()) + { + oprot.writeString(_iter4.getKey()); + oprot.writeString(_iter4.getValue()); + } + oprot.writeMapEnd(); + } + oprot.writeFieldEnd(); + } + } + if (struct.m != null) { + oprot.writeFieldBegin(M_FIELD_DESC); + struct.m.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.priority != null) { + if (struct.isSetPriority()) { + oprot.writeFieldBegin(PRIORITY_FIELD_DESC); + oprot.writeI32(struct.priority.getValue()); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class LoggingEventTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggingEventTupleScheme getScheme() { + return new LoggingEventTupleScheme(); + } + } + + private static class LoggingEventTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, LoggingEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.id); + oprot.writeString(struct.origin); + oprot.writeI64(struct.time); + struct.m.write(oprot); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetV()) { + optionals.set(0); + } + if (struct.isSetMetadata()) { + optionals.set(1); + } + if (struct.isSetPriority()) { + optionals.set(2); + } + oprot.writeBitSet(optionals, 3); + if (struct.isSetV()) { + oprot.writeI16(struct.v); + } + if (struct.isSetMetadata()) { + { + oprot.writeI32(struct.metadata.size()); + for (java.util.Map.Entry _iter5 : struct.metadata.entrySet()) + { + oprot.writeString(_iter5.getKey()); + oprot.writeString(_iter5.getValue()); + } + } + } + if (struct.isSetPriority()) { + oprot.writeI32(struct.priority.getValue()); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, LoggingEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.id = iprot.readString(); + struct.setIdIsSet(true); + struct.origin = iprot.readString(); + struct.setOriginIsSet(true); + struct.time = iprot.readI64(); + struct.setTimeIsSet(true); + struct.m = new LoggingEventPayload(); + struct.m.read(iprot); + struct.setMIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(3); + if (incoming.get(0)) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } + if (incoming.get(1)) { + { + org.apache.thrift.protocol.TMap _map6 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, iprot.readI32()); + struct.metadata = new java.util.HashMap(2*_map6.size); + @org.apache.thrift.annotation.Nullable java.lang.String _key7; + @org.apache.thrift.annotation.Nullable java.lang.String _val8; + for (int _i9 = 0; _i9 < _map6.size; ++_i9) + { + _key7 = iprot.readString(); + _val8 = iprot.readString(); + struct.metadata.put(_key7, _val8); + } + } + struct.setMetadataIsSet(true); + } + if (incoming.get(2)) { + struct.priority = com.chriniko.pollfish.thrift.server.protocol.LoggingEventPriority.findByValue(iprot.readI32()); + struct.setPriorityIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPayload.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPayload.java new file mode 100644 index 0000000..df42f3d --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPayload.java @@ -0,0 +1,408 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggingEventPayload extends org.apache.thrift.TUnion { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("LoggingEventPayload"); + private static final org.apache.thrift.protocol.TField MONITOR_SERVICE_EVENT_FIELD_DESC = new org.apache.thrift.protocol.TField("monitorServiceEvent", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField TRANSACTION_EVENT_FIELD_DESC = new org.apache.thrift.protocol.TField("transactionEvent", org.apache.thrift.protocol.TType.STRUCT, (short)2); + private static final org.apache.thrift.protocol.TField USER_INFO_EVENT_FIELD_DESC = new org.apache.thrift.protocol.TField("userInfoEvent", org.apache.thrift.protocol.TType.STRUCT, (short)3); + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + MONITOR_SERVICE_EVENT((short)1, "monitorServiceEvent"), + TRANSACTION_EVENT((short)2, "transactionEvent"), + USER_INFO_EVENT((short)3, "userInfoEvent"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // MONITOR_SERVICE_EVENT + return MONITOR_SERVICE_EVENT; + case 2: // TRANSACTION_EVENT + return TRANSACTION_EVENT; + case 3: // USER_INFO_EVENT + return USER_INFO_EVENT; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.MONITOR_SERVICE_EVENT, new org.apache.thrift.meta_data.FieldMetaData("monitorServiceEvent", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, MonitorServiceEvent.class))); + tmpMap.put(_Fields.TRANSACTION_EVENT, new org.apache.thrift.meta_data.FieldMetaData("transactionEvent", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TransactionEvent.class))); + tmpMap.put(_Fields.USER_INFO_EVENT, new org.apache.thrift.meta_data.FieldMetaData("userInfoEvent", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, UserInfoEvent.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(LoggingEventPayload.class, metaDataMap); + } + + public LoggingEventPayload() { + super(); + } + + public LoggingEventPayload(_Fields setField, java.lang.Object value) { + super(setField, value); + } + + public LoggingEventPayload(LoggingEventPayload other) { + super(other); + } + public LoggingEventPayload deepCopy() { + return new LoggingEventPayload(this); + } + + public static LoggingEventPayload monitorServiceEvent(MonitorServiceEvent value) { + LoggingEventPayload x = new LoggingEventPayload(); + x.setMonitorServiceEvent(value); + return x; + } + + public static LoggingEventPayload transactionEvent(TransactionEvent value) { + LoggingEventPayload x = new LoggingEventPayload(); + x.setTransactionEvent(value); + return x; + } + + public static LoggingEventPayload userInfoEvent(UserInfoEvent value) { + LoggingEventPayload x = new LoggingEventPayload(); + x.setUserInfoEvent(value); + return x; + } + + + @Override + protected void checkType(_Fields setField, java.lang.Object value) throws java.lang.ClassCastException { + switch (setField) { + case MONITOR_SERVICE_EVENT: + if (value instanceof MonitorServiceEvent) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type MonitorServiceEvent for field 'monitorServiceEvent', but got " + value.getClass().getSimpleName()); + case TRANSACTION_EVENT: + if (value instanceof TransactionEvent) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type TransactionEvent for field 'transactionEvent', but got " + value.getClass().getSimpleName()); + case USER_INFO_EVENT: + if (value instanceof UserInfoEvent) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type UserInfoEvent for field 'userInfoEvent', but got " + value.getClass().getSimpleName()); + default: + throw new java.lang.IllegalArgumentException("Unknown field id " + setField); + } + } + + @Override + protected java.lang.Object standardSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TField field) throws org.apache.thrift.TException { + _Fields setField = _Fields.findByThriftId(field.id); + if (setField != null) { + switch (setField) { + case MONITOR_SERVICE_EVENT: + if (field.type == MONITOR_SERVICE_EVENT_FIELD_DESC.type) { + MonitorServiceEvent monitorServiceEvent; + monitorServiceEvent = new MonitorServiceEvent(); + monitorServiceEvent.read(iprot); + return monitorServiceEvent; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + case TRANSACTION_EVENT: + if (field.type == TRANSACTION_EVENT_FIELD_DESC.type) { + TransactionEvent transactionEvent; + transactionEvent = new TransactionEvent(); + transactionEvent.read(iprot); + return transactionEvent; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + case USER_INFO_EVENT: + if (field.type == USER_INFO_EVENT_FIELD_DESC.type) { + UserInfoEvent userInfoEvent; + userInfoEvent = new UserInfoEvent(); + userInfoEvent.read(iprot); + return userInfoEvent; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + default: + throw new java.lang.IllegalStateException("setField wasn't null, but didn't match any of the case statements!"); + } + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + } + + @Override + protected void standardSchemeWriteValue(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + switch (setField_) { + case MONITOR_SERVICE_EVENT: + MonitorServiceEvent monitorServiceEvent = (MonitorServiceEvent)value_; + monitorServiceEvent.write(oprot); + return; + case TRANSACTION_EVENT: + TransactionEvent transactionEvent = (TransactionEvent)value_; + transactionEvent.write(oprot); + return; + case USER_INFO_EVENT: + UserInfoEvent userInfoEvent = (UserInfoEvent)value_; + userInfoEvent.write(oprot); + return; + default: + throw new java.lang.IllegalStateException("Cannot write union with unknown field " + setField_); + } + } + + @Override + protected java.lang.Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException { + _Fields setField = _Fields.findByThriftId(fieldID); + if (setField != null) { + switch (setField) { + case MONITOR_SERVICE_EVENT: + MonitorServiceEvent monitorServiceEvent; + monitorServiceEvent = new MonitorServiceEvent(); + monitorServiceEvent.read(iprot); + return monitorServiceEvent; + case TRANSACTION_EVENT: + TransactionEvent transactionEvent; + transactionEvent = new TransactionEvent(); + transactionEvent.read(iprot); + return transactionEvent; + case USER_INFO_EVENT: + UserInfoEvent userInfoEvent; + userInfoEvent = new UserInfoEvent(); + userInfoEvent.read(iprot); + return userInfoEvent; + default: + throw new java.lang.IllegalStateException("setField wasn't null, but didn't match any of the case statements!"); + } + } else { + throw new org.apache.thrift.protocol.TProtocolException("Couldn't find a field with field id " + fieldID); + } + } + + @Override + protected void tupleSchemeWriteValue(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + switch (setField_) { + case MONITOR_SERVICE_EVENT: + MonitorServiceEvent monitorServiceEvent = (MonitorServiceEvent)value_; + monitorServiceEvent.write(oprot); + return; + case TRANSACTION_EVENT: + TransactionEvent transactionEvent = (TransactionEvent)value_; + transactionEvent.write(oprot); + return; + case USER_INFO_EVENT: + UserInfoEvent userInfoEvent = (UserInfoEvent)value_; + userInfoEvent.write(oprot); + return; + default: + throw new java.lang.IllegalStateException("Cannot write union with unknown field " + setField_); + } + } + + @Override + protected org.apache.thrift.protocol.TField getFieldDesc(_Fields setField) { + switch (setField) { + case MONITOR_SERVICE_EVENT: + return MONITOR_SERVICE_EVENT_FIELD_DESC; + case TRANSACTION_EVENT: + return TRANSACTION_EVENT_FIELD_DESC; + case USER_INFO_EVENT: + return USER_INFO_EVENT_FIELD_DESC; + default: + throw new java.lang.IllegalArgumentException("Unknown field id " + setField); + } + } + + @Override + protected org.apache.thrift.protocol.TStruct getStructDesc() { + return STRUCT_DESC; + } + + @Override + protected _Fields enumForId(short id) { + return _Fields.findByThriftIdOrThrow(id); + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public MonitorServiceEvent getMonitorServiceEvent() { + if (getSetField() == _Fields.MONITOR_SERVICE_EVENT) { + return (MonitorServiceEvent)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'monitorServiceEvent' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setMonitorServiceEvent(MonitorServiceEvent value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.MONITOR_SERVICE_EVENT; + value_ = value; + } + + public TransactionEvent getTransactionEvent() { + if (getSetField() == _Fields.TRANSACTION_EVENT) { + return (TransactionEvent)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'transactionEvent' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setTransactionEvent(TransactionEvent value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.TRANSACTION_EVENT; + value_ = value; + } + + public UserInfoEvent getUserInfoEvent() { + if (getSetField() == _Fields.USER_INFO_EVENT) { + return (UserInfoEvent)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'userInfoEvent' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setUserInfoEvent(UserInfoEvent value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.USER_INFO_EVENT; + value_ = value; + } + + public boolean isSetMonitorServiceEvent() { + return setField_ == _Fields.MONITOR_SERVICE_EVENT; + } + + + public boolean isSetTransactionEvent() { + return setField_ == _Fields.TRANSACTION_EVENT; + } + + + public boolean isSetUserInfoEvent() { + return setField_ == _Fields.USER_INFO_EVENT; + } + + + public boolean equals(java.lang.Object other) { + if (other instanceof LoggingEventPayload) { + return equals((LoggingEventPayload)other); + } else { + return false; + } + } + + public boolean equals(LoggingEventPayload other) { + return other != null && getSetField() == other.getSetField() && getFieldValue().equals(other.getFieldValue()); + } + + @Override + public int compareTo(LoggingEventPayload other) { + int lastComparison = org.apache.thrift.TBaseHelper.compareTo(getSetField(), other.getSetField()); + if (lastComparison == 0) { + return org.apache.thrift.TBaseHelper.compareTo(getFieldValue(), other.getFieldValue()); + } + return lastComparison; + } + + + @Override + public int hashCode() { + java.util.List list = new java.util.ArrayList(); + list.add(this.getClass().getName()); + org.apache.thrift.TFieldIdEnum setField = getSetField(); + if (setField != null) { + list.add(setField.getThriftFieldId()); + java.lang.Object value = getFieldValue(); + if (value instanceof org.apache.thrift.TEnum) { + list.add(((org.apache.thrift.TEnum)getFieldValue()).getValue()); + } else { + list.add(value); + } + } + return list.hashCode(); + } + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPriority.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPriority.java new file mode 100644 index 0000000..2d2e80f --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventPriority.java @@ -0,0 +1,46 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + + +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public enum LoggingEventPriority implements org.apache.thrift.TEnum { + NORMAL(0), + MEDIUM(1), + CRITICAL(2); + + private final int value; + + private LoggingEventPriority(int value) { + this.value = value; + } + + /** + * Get the integer value of this enum value, as defined in the Thrift IDL. + */ + public int getValue() { + return value; + } + + /** + * Find a the enum type by its integer value, as defined in the Thrift IDL. + * @return null if the value is not found. + */ + @org.apache.thrift.annotation.Nullable + public static LoggingEventPriority findByValue(int value) { + switch (value) { + case 0: + return NORMAL; + case 1: + return MEDIUM; + case 2: + return CRITICAL; + default: + return null; + } + } +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventService.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventService.java new file mode 100644 index 0000000..3f83bbd --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventService.java @@ -0,0 +1,2980 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggingEventService { + + public interface Iface { + + public LoggingEvent save(LoggingEvent evt) throws NotValidInputException, org.apache.thrift.TException; + + public java.util.Set batchSave(java.util.Set evts) throws NotValidInputException, org.apache.thrift.TException; + + public LoggingEventServiceHealthStatus healthStatus() throws org.apache.thrift.TException; + + } + + public interface AsyncIface { + + public void save(LoggingEvent evt, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void batchSave(java.util.Set evts, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException; + + public void healthStatus(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + } + + public static class Client extends org.apache.thrift.TServiceClient implements Iface { + public static class Factory implements org.apache.thrift.TServiceClientFactory { + public Factory() {} + public Client getClient(org.apache.thrift.protocol.TProtocol prot) { + return new Client(prot); + } + public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + return new Client(iprot, oprot); + } + } + + public Client(org.apache.thrift.protocol.TProtocol prot) + { + super(prot, prot); + } + + public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { + super(iprot, oprot); + } + + public LoggingEvent save(LoggingEvent evt) throws NotValidInputException, org.apache.thrift.TException + { + send_save(evt); + return recv_save(); + } + + public void send_save(LoggingEvent evt) throws org.apache.thrift.TException + { + save_args args = new save_args(); + args.setEvt(evt); + sendBase("save", args); + } + + public LoggingEvent recv_save() throws NotValidInputException, org.apache.thrift.TException + { + save_result result = new save_result(); + receiveBase(result, "save"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.e != null) { + throw result.e; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "save failed: unknown result"); + } + + public java.util.Set batchSave(java.util.Set evts) throws NotValidInputException, org.apache.thrift.TException + { + send_batchSave(evts); + return recv_batchSave(); + } + + public void send_batchSave(java.util.Set evts) throws org.apache.thrift.TException + { + batchSave_args args = new batchSave_args(); + args.setEvts(evts); + sendBase("batchSave", args); + } + + public java.util.Set recv_batchSave() throws NotValidInputException, org.apache.thrift.TException + { + batchSave_result result = new batchSave_result(); + receiveBase(result, "batchSave"); + if (result.isSetSuccess()) { + return result.success; + } + if (result.e != null) { + throw result.e; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "batchSave failed: unknown result"); + } + + public LoggingEventServiceHealthStatus healthStatus() throws org.apache.thrift.TException + { + send_healthStatus(); + return recv_healthStatus(); + } + + public void send_healthStatus() throws org.apache.thrift.TException + { + healthStatus_args args = new healthStatus_args(); + sendBase("healthStatus", args); + } + + public LoggingEventServiceHealthStatus recv_healthStatus() throws org.apache.thrift.TException + { + healthStatus_result result = new healthStatus_result(); + receiveBase(result, "healthStatus"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "healthStatus failed: unknown result"); + } + + } + public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { + public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { + private org.apache.thrift.async.TAsyncClientManager clientManager; + private org.apache.thrift.protocol.TProtocolFactory protocolFactory; + public Factory(org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.protocol.TProtocolFactory protocolFactory) { + this.clientManager = clientManager; + this.protocolFactory = protocolFactory; + } + public AsyncClient getAsyncClient(org.apache.thrift.transport.TNonblockingTransport transport) { + return new AsyncClient(protocolFactory, clientManager, transport); + } + } + + public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.async.TAsyncClientManager clientManager, org.apache.thrift.transport.TNonblockingTransport transport) { + super(protocolFactory, clientManager, transport); + } + + public void save(LoggingEvent evt, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + save_call method_call = new save_call(evt, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class save_call extends org.apache.thrift.async.TAsyncMethodCall { + private LoggingEvent evt; + public save_call(LoggingEvent evt, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.evt = evt; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("save", org.apache.thrift.protocol.TMessageType.CALL, 0)); + save_args args = new save_args(); + args.setEvt(evt); + args.write(prot); + prot.writeMessageEnd(); + } + + public LoggingEvent getResult() throws NotValidInputException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_save(); + } + } + + public void batchSave(java.util.Set evts, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + checkReady(); + batchSave_call method_call = new batchSave_call(evts, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class batchSave_call extends org.apache.thrift.async.TAsyncMethodCall> { + private java.util.Set evts; + public batchSave_call(java.util.Set evts, org.apache.thrift.async.AsyncMethodCallback> resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.evts = evts; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("batchSave", org.apache.thrift.protocol.TMessageType.CALL, 0)); + batchSave_args args = new batchSave_args(); + args.setEvts(evts); + args.write(prot); + prot.writeMessageEnd(); + } + + public java.util.Set getResult() throws NotValidInputException, org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_batchSave(); + } + } + + public void healthStatus(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + healthStatus_call method_call = new healthStatus_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class healthStatus_call extends org.apache.thrift.async.TAsyncMethodCall { + public healthStatus_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("healthStatus", org.apache.thrift.protocol.TMessageType.CALL, 0)); + healthStatus_args args = new healthStatus_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public LoggingEventServiceHealthStatus getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new java.lang.IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_healthStatus(); + } + } + + } + + public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(Processor.class.getName()); + public Processor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected Processor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("save", new save()); + processMap.put("batchSave", new batchSave()); + processMap.put("healthStatus", new healthStatus()); + return processMap; + } + + public static class save extends org.apache.thrift.ProcessFunction { + public save() { + super("save"); + } + + public save_args getEmptyArgsInstance() { + return new save_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public save_result getResult(I iface, save_args args) throws org.apache.thrift.TException { + save_result result = new save_result(); + try { + result.success = iface.save(args.evt); + } catch (NotValidInputException e) { + result.e = e; + } + return result; + } + } + + public static class batchSave extends org.apache.thrift.ProcessFunction { + public batchSave() { + super("batchSave"); + } + + public batchSave_args getEmptyArgsInstance() { + return new batchSave_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public batchSave_result getResult(I iface, batchSave_args args) throws org.apache.thrift.TException { + batchSave_result result = new batchSave_result(); + try { + result.success = iface.batchSave(args.evts); + } catch (NotValidInputException e) { + result.e = e; + } + return result; + } + } + + public static class healthStatus extends org.apache.thrift.ProcessFunction { + public healthStatus() { + super("healthStatus"); + } + + public healthStatus_args getEmptyArgsInstance() { + return new healthStatus_args(); + } + + protected boolean isOneway() { + return false; + } + + @Override + protected boolean rethrowUnhandledExceptions() { + return false; + } + + public healthStatus_result getResult(I iface, healthStatus_args args) throws org.apache.thrift.TException { + healthStatus_result result = new healthStatus_result(); + result.success = iface.healthStatus(); + return result; + } + } + + } + + public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { + private static final org.slf4j.Logger _LOGGER = org.slf4j.LoggerFactory.getLogger(AsyncProcessor.class.getName()); + public AsyncProcessor(I iface) { + super(iface, getProcessMap(new java.util.HashMap>())); + } + + protected AsyncProcessor(I iface, java.util.Map> processMap) { + super(iface, getProcessMap(processMap)); + } + + private static java.util.Map> getProcessMap(java.util.Map> processMap) { + processMap.put("save", new save()); + processMap.put("batchSave", new batchSave()); + processMap.put("healthStatus", new healthStatus()); + return processMap; + } + + public static class save extends org.apache.thrift.AsyncProcessFunction { + public save() { + super("save"); + } + + public save_args getEmptyArgsInstance() { + return new save_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(LoggingEvent o) { + save_result result = new save_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + save_result result = new save_result(); + if (e instanceof NotValidInputException) { + result.e = (NotValidInputException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, save_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.save(args.evt,resultHandler); + } + } + + public static class batchSave extends org.apache.thrift.AsyncProcessFunction> { + public batchSave() { + super("batchSave"); + } + + public batchSave_args getEmptyArgsInstance() { + return new batchSave_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback> getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback>() { + public void onComplete(java.util.Set o) { + batchSave_result result = new batchSave_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + batchSave_result result = new batchSave_result(); + if (e instanceof NotValidInputException) { + result.e = (NotValidInputException) e; + result.setEIsSet(true); + msg = result; + } else if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, batchSave_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws org.apache.thrift.TException { + iface.batchSave(args.evts,resultHandler); + } + } + + public static class healthStatus extends org.apache.thrift.AsyncProcessFunction { + public healthStatus() { + super("healthStatus"); + } + + public healthStatus_args getEmptyArgsInstance() { + return new healthStatus_args(); + } + + public org.apache.thrift.async.AsyncMethodCallback getResultHandler(final org.apache.thrift.server.AbstractNonblockingServer.AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new org.apache.thrift.async.AsyncMethodCallback() { + public void onComplete(LoggingEventServiceHealthStatus o) { + healthStatus_result result = new healthStatus_result(); + result.success = o; + try { + fcall.sendResponse(fb, result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + } catch (org.apache.thrift.transport.TTransportException e) { + _LOGGER.error("TTransportException writing to internal frame buffer", e); + fb.close(); + } catch (java.lang.Exception e) { + _LOGGER.error("Exception writing to internal frame buffer", e); + onError(e); + } + } + public void onError(java.lang.Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TSerializable msg; + healthStatus_result result = new healthStatus_result(); + if (e instanceof org.apache.thrift.transport.TTransportException) { + _LOGGER.error("TTransportException inside handler", e); + fb.close(); + return; + } else if (e instanceof org.apache.thrift.TApplicationException) { + _LOGGER.error("TApplicationException inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TApplicationException)e; + } else { + _LOGGER.error("Exception inside handler", e); + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + } catch (java.lang.Exception ex) { + _LOGGER.error("Exception writing to internal frame buffer", ex); + fb.close(); + } + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, healthStatus_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + iface.healthStatus(resultHandler); + } + } + + } + + public static class save_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("save_args"); + + private static final org.apache.thrift.protocol.TField EVT_FIELD_DESC = new org.apache.thrift.protocol.TField("evt", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new save_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new save_argsTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable LoggingEvent evt; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + EVT((short)1, "evt"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // EVT + return EVT; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.EVT, new org.apache.thrift.meta_data.FieldMetaData("evt", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEvent.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(save_args.class, metaDataMap); + } + + public save_args() { + } + + public save_args( + LoggingEvent evt) + { + this(); + this.evt = evt; + } + + /** + * Performs a deep copy on other. + */ + public save_args(save_args other) { + if (other.isSetEvt()) { + this.evt = new LoggingEvent(other.evt); + } + } + + public save_args deepCopy() { + return new save_args(this); + } + + @Override + public void clear() { + this.evt = null; + } + + @org.apache.thrift.annotation.Nullable + public LoggingEvent getEvt() { + return this.evt; + } + + public save_args setEvt(@org.apache.thrift.annotation.Nullable LoggingEvent evt) { + this.evt = evt; + return this; + } + + public void unsetEvt() { + this.evt = null; + } + + /** Returns true if field evt is set (has been assigned a value) and false otherwise */ + public boolean isSetEvt() { + return this.evt != null; + } + + public void setEvtIsSet(boolean value) { + if (!value) { + this.evt = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case EVT: + if (value == null) { + unsetEvt(); + } else { + setEvt((LoggingEvent)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case EVT: + return getEvt(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case EVT: + return isSetEvt(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof save_args) + return this.equals((save_args)that); + return false; + } + + public boolean equals(save_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_evt = true && this.isSetEvt(); + boolean that_present_evt = true && that.isSetEvt(); + if (this_present_evt || that_present_evt) { + if (!(this_present_evt && that_present_evt)) + return false; + if (!this.evt.equals(that.evt)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetEvt()) ? 131071 : 524287); + if (isSetEvt()) + hashCode = hashCode * 8191 + evt.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(save_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetEvt()).compareTo(other.isSetEvt()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetEvt()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.evt, other.evt); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("save_args("); + boolean first = true; + + sb.append("evt:"); + if (this.evt == null) { + sb.append("null"); + } else { + sb.append(this.evt); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (evt != null) { + evt.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class save_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_argsStandardScheme getScheme() { + return new save_argsStandardScheme(); + } + } + + private static class save_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // EVT + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.evt = new LoggingEvent(); + struct.evt.read(iprot); + struct.setEvtIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, save_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.evt != null) { + oprot.writeFieldBegin(EVT_FIELD_DESC); + struct.evt.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class save_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_argsTupleScheme getScheme() { + return new save_argsTupleScheme(); + } + } + + private static class save_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetEvt()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetEvt()) { + struct.evt.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, save_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.evt = new LoggingEvent(); + struct.evt.read(iprot); + struct.setEvtIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class save_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("save_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new save_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new save_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable LoggingEvent success; // required + public @org.apache.thrift.annotation.Nullable NotValidInputException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // E + return E; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEvent.class))); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, NotValidInputException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(save_result.class, metaDataMap); + } + + public save_result() { + } + + public save_result( + LoggingEvent success, + NotValidInputException e) + { + this(); + this.success = success; + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public save_result(save_result other) { + if (other.isSetSuccess()) { + this.success = new LoggingEvent(other.success); + } + if (other.isSetE()) { + this.e = new NotValidInputException(other.e); + } + } + + public save_result deepCopy() { + return new save_result(this); + } + + @Override + public void clear() { + this.success = null; + this.e = null; + } + + @org.apache.thrift.annotation.Nullable + public LoggingEvent getSuccess() { + return this.success; + } + + public save_result setSuccess(@org.apache.thrift.annotation.Nullable LoggingEvent 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; + } + } + + @org.apache.thrift.annotation.Nullable + public NotValidInputException getE() { + return this.e; + } + + public save_result setE(@org.apache.thrift.annotation.Nullable NotValidInputException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((LoggingEvent)value); + } + break; + + case E: + if (value == null) { + unsetE(); + } else { + setE((NotValidInputException)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof save_result) + return this.equals((save_result)that); + return false; + } + + public boolean equals(save_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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; + } + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(save_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("save_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class save_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_resultStandardScheme getScheme() { + return new save_resultStandardScheme(); + } + } + + private static class save_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new LoggingEvent(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new NotValidInputException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, save_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class save_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public save_resultTupleScheme getScheme() { + return new save_resultTupleScheme(); + } + } + + private static class save_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetE()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, save_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = new LoggingEvent(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.e = new NotValidInputException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class batchSave_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batchSave_args"); + + private static final org.apache.thrift.protocol.TField EVTS_FIELD_DESC = new org.apache.thrift.protocol.TField("evts", org.apache.thrift.protocol.TType.SET, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batchSave_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batchSave_argsTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.Set evts; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + EVTS((short)1, "evts"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // EVTS + return EVTS; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.EVTS, new org.apache.thrift.meta_data.FieldMetaData("evts", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEvent.class)))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batchSave_args.class, metaDataMap); + } + + public batchSave_args() { + } + + public batchSave_args( + java.util.Set evts) + { + this(); + this.evts = evts; + } + + /** + * Performs a deep copy on other. + */ + public batchSave_args(batchSave_args other) { + if (other.isSetEvts()) { + java.util.Set __this__evts = new java.util.HashSet(other.evts.size()); + for (LoggingEvent other_element : other.evts) { + __this__evts.add(new LoggingEvent(other_element)); + } + this.evts = __this__evts; + } + } + + public batchSave_args deepCopy() { + return new batchSave_args(this); + } + + @Override + public void clear() { + this.evts = null; + } + + public int getEvtsSize() { + return (this.evts == null) ? 0 : this.evts.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getEvtsIterator() { + return (this.evts == null) ? null : this.evts.iterator(); + } + + public void addToEvts(LoggingEvent elem) { + if (this.evts == null) { + this.evts = new java.util.HashSet(); + } + this.evts.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Set getEvts() { + return this.evts; + } + + public batchSave_args setEvts(@org.apache.thrift.annotation.Nullable java.util.Set evts) { + this.evts = evts; + return this; + } + + public void unsetEvts() { + this.evts = null; + } + + /** Returns true if field evts is set (has been assigned a value) and false otherwise */ + public boolean isSetEvts() { + return this.evts != null; + } + + public void setEvtsIsSet(boolean value) { + if (!value) { + this.evts = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case EVTS: + if (value == null) { + unsetEvts(); + } else { + setEvts((java.util.Set)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case EVTS: + return getEvts(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case EVTS: + return isSetEvts(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batchSave_args) + return this.equals((batchSave_args)that); + return false; + } + + public boolean equals(batchSave_args that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_evts = true && this.isSetEvts(); + boolean that_present_evts = true && that.isSetEvts(); + if (this_present_evts || that_present_evts) { + if (!(this_present_evts && that_present_evts)) + return false; + if (!this.evts.equals(that.evts)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetEvts()) ? 131071 : 524287); + if (isSetEvts()) + hashCode = hashCode * 8191 + evts.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batchSave_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetEvts()).compareTo(other.isSetEvts()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetEvts()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.evts, other.evts); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batchSave_args("); + boolean first = true; + + sb.append("evts:"); + if (this.evts == null) { + sb.append("null"); + } else { + sb.append(this.evts); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batchSave_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batchSave_argsStandardScheme getScheme() { + return new batchSave_argsStandardScheme(); + } + } + + private static class batchSave_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batchSave_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // EVTS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set10 = iprot.readSetBegin(); + struct.evts = new java.util.HashSet(2*_set10.size); + @org.apache.thrift.annotation.Nullable LoggingEvent _elem11; + for (int _i12 = 0; _i12 < _set10.size; ++_i12) + { + _elem11 = new LoggingEvent(); + _elem11.read(iprot); + struct.evts.add(_elem11); + } + iprot.readSetEnd(); + } + struct.setEvtsIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batchSave_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.evts != null) { + oprot.writeFieldBegin(EVTS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.evts.size())); + for (LoggingEvent _iter13 : struct.evts) + { + _iter13.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batchSave_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batchSave_argsTupleScheme getScheme() { + return new batchSave_argsTupleScheme(); + } + } + + private static class batchSave_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batchSave_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetEvts()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetEvts()) { + { + oprot.writeI32(struct.evts.size()); + for (LoggingEvent _iter14 : struct.evts) + { + _iter14.write(oprot); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batchSave_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TSet _set15 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.evts = new java.util.HashSet(2*_set15.size); + @org.apache.thrift.annotation.Nullable LoggingEvent _elem16; + for (int _i17 = 0; _i17 < _set15.size; ++_i17) + { + _elem16 = new LoggingEvent(); + _elem16.read(iprot); + struct.evts.add(_elem16); + } + } + struct.setEvtsIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class batchSave_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("batchSave_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.SET, (short)0); + private static final org.apache.thrift.protocol.TField E_FIELD_DESC = new org.apache.thrift.protocol.TField("e", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new batchSave_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new batchSave_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable java.util.Set success; // required + public @org.apache.thrift.annotation.Nullable NotValidInputException e; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + E((short)1, "e"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // E + return E; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.SetMetaData(org.apache.thrift.protocol.TType.SET, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEvent.class)))); + tmpMap.put(_Fields.E, new org.apache.thrift.meta_data.FieldMetaData("e", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, NotValidInputException.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(batchSave_result.class, metaDataMap); + } + + public batchSave_result() { + } + + public batchSave_result( + java.util.Set success, + NotValidInputException e) + { + this(); + this.success = success; + this.e = e; + } + + /** + * Performs a deep copy on other. + */ + public batchSave_result(batchSave_result other) { + if (other.isSetSuccess()) { + java.util.Set __this__success = new java.util.HashSet(other.success.size()); + for (LoggingEvent other_element : other.success) { + __this__success.add(new LoggingEvent(other_element)); + } + this.success = __this__success; + } + if (other.isSetE()) { + this.e = new NotValidInputException(other.e); + } + } + + public batchSave_result deepCopy() { + return new batchSave_result(this); + } + + @Override + public void clear() { + this.success = null; + this.e = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(LoggingEvent elem) { + if (this.success == null) { + this.success = new java.util.HashSet(); + } + this.success.add(elem); + } + + @org.apache.thrift.annotation.Nullable + public java.util.Set getSuccess() { + return this.success; + } + + public batchSave_result setSuccess(@org.apache.thrift.annotation.Nullable java.util.Set 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; + } + } + + @org.apache.thrift.annotation.Nullable + public NotValidInputException getE() { + return this.e; + } + + public batchSave_result setE(@org.apache.thrift.annotation.Nullable NotValidInputException e) { + this.e = e; + return this; + } + + public void unsetE() { + this.e = null; + } + + /** Returns true if field e is set (has been assigned a value) and false otherwise */ + public boolean isSetE() { + return this.e != null; + } + + public void setEIsSet(boolean value) { + if (!value) { + this.e = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((java.util.Set)value); + } + break; + + case E: + if (value == null) { + unsetE(); + } else { + setE((NotValidInputException)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case E: + return getE(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case E: + return isSetE(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof batchSave_result) + return this.equals((batchSave_result)that); + return false; + } + + public boolean equals(batchSave_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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; + } + + boolean this_present_e = true && this.isSetE(); + boolean that_present_e = true && that.isSetE(); + if (this_present_e || that_present_e) { + if (!(this_present_e && that_present_e)) + return false; + if (!this.e.equals(that.e)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + hashCode = hashCode * 8191 + ((isSetE()) ? 131071 : 524287); + if (isSetE()) + hashCode = hashCode * 8191 + e.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(batchSave_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetE()).compareTo(other.isSetE()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetE()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.e, other.e); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("batchSave_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("e:"); + if (this.e == null) { + sb.append("null"); + } else { + sb.append(this.e); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class batchSave_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batchSave_resultStandardScheme getScheme() { + return new batchSave_resultStandardScheme(); + } + } + + private static class batchSave_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, batchSave_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.SET) { + { + org.apache.thrift.protocol.TSet _set18 = iprot.readSetBegin(); + struct.success = new java.util.HashSet(2*_set18.size); + @org.apache.thrift.annotation.Nullable LoggingEvent _elem19; + for (int _i20 = 0; _i20 < _set18.size; ++_i20) + { + _elem19 = new LoggingEvent(); + _elem19.read(iprot); + struct.success.add(_elem19); + } + iprot.readSetEnd(); + } + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // E + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.e = new NotValidInputException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, batchSave_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeSetBegin(new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, struct.success.size())); + for (LoggingEvent _iter21 : struct.success) + { + _iter21.write(oprot); + } + oprot.writeSetEnd(); + } + oprot.writeFieldEnd(); + } + if (struct.e != null) { + oprot.writeFieldBegin(E_FIELD_DESC); + struct.e.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class batchSave_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public batchSave_resultTupleScheme getScheme() { + return new batchSave_resultTupleScheme(); + } + } + + private static class batchSave_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, batchSave_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetE()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (LoggingEvent _iter22 : struct.success) + { + _iter22.write(oprot); + } + } + } + if (struct.isSetE()) { + struct.e.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, batchSave_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TSet _set23 = new org.apache.thrift.protocol.TSet(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); + struct.success = new java.util.HashSet(2*_set23.size); + @org.apache.thrift.annotation.Nullable LoggingEvent _elem24; + for (int _i25 = 0; _i25 < _set23.size; ++_i25) + { + _elem24 = new LoggingEvent(); + _elem24.read(iprot); + struct.success.add(_elem24); + } + } + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.e = new NotValidInputException(); + struct.e.read(iprot); + struct.setEIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class healthStatus_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("healthStatus_args"); + + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new healthStatus_argsStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new healthStatus_argsTupleSchemeFactory(); + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(healthStatus_args.class, metaDataMap); + } + + public healthStatus_args() { + } + + /** + * Performs a deep copy on other. + */ + public healthStatus_args(healthStatus_args other) { + } + + public healthStatus_args deepCopy() { + return new healthStatus_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof healthStatus_args) + return this.equals((healthStatus_args)that); + return false; + } + + public boolean equals(healthStatus_args that) { + if (that == null) + return false; + if (this == that) + return true; + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + return hashCode; + } + + @Override + public int compareTo(healthStatus_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("healthStatus_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class healthStatus_argsStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public healthStatus_argsStandardScheme getScheme() { + return new healthStatus_argsStandardScheme(); + } + } + + private static class healthStatus_argsStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, healthStatus_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, healthStatus_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class healthStatus_argsTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public healthStatus_argsTupleScheme getScheme() { + return new healthStatus_argsTupleScheme(); + } + } + + private static class healthStatus_argsTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, healthStatus_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, healthStatus_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + + public static class healthStatus_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("healthStatus_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new healthStatus_resultStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new healthStatus_resultTupleSchemeFactory(); + + public @org.apache.thrift.annotation.Nullable LoggingEventServiceHealthStatus success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, LoggingEventServiceHealthStatus.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(healthStatus_result.class, metaDataMap); + } + + public healthStatus_result() { + } + + public healthStatus_result( + LoggingEventServiceHealthStatus success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public healthStatus_result(healthStatus_result other) { + if (other.isSetSuccess()) { + this.success = new LoggingEventServiceHealthStatus(other.success); + } + } + + public healthStatus_result deepCopy() { + return new healthStatus_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + @org.apache.thrift.annotation.Nullable + public LoggingEventServiceHealthStatus getSuccess() { + return this.success; + } + + public healthStatus_result setSuccess(@org.apache.thrift.annotation.Nullable LoggingEventServiceHealthStatus 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; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((LoggingEventServiceHealthStatus)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof healthStatus_result) + return this.equals((healthStatus_result)that); + return false; + } + + public boolean equals(healthStatus_result that) { + if (that == null) + return false; + if (this == that) + return true; + + 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; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetSuccess()) ? 131071 : 524287); + if (isSetSuccess()) + hashCode = hashCode * 8191 + success.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(healthStatus_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("healthStatus_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 org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class healthStatus_resultStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public healthStatus_resultStandardScheme getScheme() { + return new healthStatus_resultStandardScheme(); + } + } + + private static class healthStatus_resultStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, healthStatus_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new LoggingEventServiceHealthStatus(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, healthStatus_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class healthStatus_resultTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public healthStatus_resultTupleScheme getScheme() { + return new healthStatus_resultTupleScheme(); + } + } + + private static class healthStatus_resultTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, healthStatus_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, healthStatus_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = new LoggingEventServiceHealthStatus(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } + } + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventServiceHealthStatus.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventServiceHealthStatus.java new file mode 100644 index 0000000..05317cb --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/LoggingEventServiceHealthStatus.java @@ -0,0 +1,490 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class LoggingEventServiceHealthStatus implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("LoggingEventServiceHealthStatus"); + + private static final org.apache.thrift.protocol.TField HEALTHY_FIELD_DESC = new org.apache.thrift.protocol.TField("healthy", org.apache.thrift.protocol.TType.BOOL, (short)1); + private static final org.apache.thrift.protocol.TField MSG_FIELD_DESC = new org.apache.thrift.protocol.TField("msg", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new LoggingEventServiceHealthStatusStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new LoggingEventServiceHealthStatusTupleSchemeFactory(); + + public boolean healthy; // required + public @org.apache.thrift.annotation.Nullable java.nio.ByteBuffer msg; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + HEALTHY((short)1, "healthy"), + MSG((short)2, "msg"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // HEALTHY + return HEALTHY; + case 2: // MSG + return MSG; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __HEALTHY_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.HEALTHY, new org.apache.thrift.meta_data.FieldMetaData("healthy", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); + tmpMap.put(_Fields.MSG, new org.apache.thrift.meta_data.FieldMetaData("msg", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(LoggingEventServiceHealthStatus.class, metaDataMap); + } + + public LoggingEventServiceHealthStatus() { + } + + public LoggingEventServiceHealthStatus( + boolean healthy, + java.nio.ByteBuffer msg) + { + this(); + this.healthy = healthy; + setHealthyIsSet(true); + this.msg = org.apache.thrift.TBaseHelper.copyBinary(msg); + } + + /** + * Performs a deep copy on other. + */ + public LoggingEventServiceHealthStatus(LoggingEventServiceHealthStatus other) { + __isset_bitfield = other.__isset_bitfield; + this.healthy = other.healthy; + if (other.isSetMsg()) { + this.msg = org.apache.thrift.TBaseHelper.copyBinary(other.msg); + } + } + + public LoggingEventServiceHealthStatus deepCopy() { + return new LoggingEventServiceHealthStatus(this); + } + + @Override + public void clear() { + setHealthyIsSet(false); + this.healthy = false; + this.msg = null; + } + + public boolean isHealthy() { + return this.healthy; + } + + public LoggingEventServiceHealthStatus setHealthy(boolean healthy) { + this.healthy = healthy; + setHealthyIsSet(true); + return this; + } + + public void unsetHealthy() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __HEALTHY_ISSET_ID); + } + + /** Returns true if field healthy is set (has been assigned a value) and false otherwise */ + public boolean isSetHealthy() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __HEALTHY_ISSET_ID); + } + + public void setHealthyIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __HEALTHY_ISSET_ID, value); + } + + public byte[] getMsg() { + setMsg(org.apache.thrift.TBaseHelper.rightSize(msg)); + return msg == null ? null : msg.array(); + } + + public java.nio.ByteBuffer bufferForMsg() { + return org.apache.thrift.TBaseHelper.copyBinary(msg); + } + + public LoggingEventServiceHealthStatus setMsg(byte[] msg) { + this.msg = msg == null ? (java.nio.ByteBuffer)null : java.nio.ByteBuffer.wrap(msg.clone()); + return this; + } + + public LoggingEventServiceHealthStatus setMsg(@org.apache.thrift.annotation.Nullable java.nio.ByteBuffer msg) { + this.msg = org.apache.thrift.TBaseHelper.copyBinary(msg); + return this; + } + + public void unsetMsg() { + this.msg = null; + } + + /** Returns true if field msg is set (has been assigned a value) and false otherwise */ + public boolean isSetMsg() { + return this.msg != null; + } + + public void setMsgIsSet(boolean value) { + if (!value) { + this.msg = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case HEALTHY: + if (value == null) { + unsetHealthy(); + } else { + setHealthy((java.lang.Boolean)value); + } + break; + + case MSG: + if (value == null) { + unsetMsg(); + } else { + if (value instanceof byte[]) { + setMsg((byte[])value); + } else { + setMsg((java.nio.ByteBuffer)value); + } + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case HEALTHY: + return isHealthy(); + + case MSG: + return getMsg(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case HEALTHY: + return isSetHealthy(); + case MSG: + return isSetMsg(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof LoggingEventServiceHealthStatus) + return this.equals((LoggingEventServiceHealthStatus)that); + return false; + } + + public boolean equals(LoggingEventServiceHealthStatus that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_healthy = true; + boolean that_present_healthy = true; + if (this_present_healthy || that_present_healthy) { + if (!(this_present_healthy && that_present_healthy)) + return false; + if (this.healthy != that.healthy) + return false; + } + + boolean this_present_msg = true && this.isSetMsg(); + boolean that_present_msg = true && that.isSetMsg(); + if (this_present_msg || that_present_msg) { + if (!(this_present_msg && that_present_msg)) + return false; + if (!this.msg.equals(that.msg)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((healthy) ? 131071 : 524287); + + hashCode = hashCode * 8191 + ((isSetMsg()) ? 131071 : 524287); + if (isSetMsg()) + hashCode = hashCode * 8191 + msg.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(LoggingEventServiceHealthStatus other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetHealthy()).compareTo(other.isSetHealthy()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetHealthy()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.healthy, other.healthy); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetMsg()).compareTo(other.isSetMsg()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetMsg()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.msg, other.msg); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("LoggingEventServiceHealthStatus("); + boolean first = true; + + sb.append("healthy:"); + sb.append(this.healthy); + first = false; + if (!first) sb.append(", "); + sb.append("msg:"); + if (this.msg == null) { + sb.append("null"); + } else { + org.apache.thrift.TBaseHelper.toString(this.msg, sb); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class LoggingEventServiceHealthStatusStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggingEventServiceHealthStatusStandardScheme getScheme() { + return new LoggingEventServiceHealthStatusStandardScheme(); + } + } + + private static class LoggingEventServiceHealthStatusStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, LoggingEventServiceHealthStatus struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // HEALTHY + if (schemeField.type == org.apache.thrift.protocol.TType.BOOL) { + struct.healthy = iprot.readBool(); + struct.setHealthyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // MSG + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.msg = iprot.readBinary(); + struct.setMsgIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, LoggingEventServiceHealthStatus struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(HEALTHY_FIELD_DESC); + oprot.writeBool(struct.healthy); + oprot.writeFieldEnd(); + if (struct.msg != null) { + oprot.writeFieldBegin(MSG_FIELD_DESC); + oprot.writeBinary(struct.msg); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class LoggingEventServiceHealthStatusTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public LoggingEventServiceHealthStatusTupleScheme getScheme() { + return new LoggingEventServiceHealthStatusTupleScheme(); + } + } + + private static class LoggingEventServiceHealthStatusTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, LoggingEventServiceHealthStatus struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetHealthy()) { + optionals.set(0); + } + if (struct.isSetMsg()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetHealthy()) { + oprot.writeBool(struct.healthy); + } + if (struct.isSetMsg()) { + oprot.writeBinary(struct.msg); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, LoggingEventServiceHealthStatus struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.healthy = iprot.readBool(); + struct.setHealthyIsSet(true); + } + if (incoming.get(1)) { + struct.msg = iprot.readBinary(); + struct.setMsgIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/MonitorServiceEvent.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/MonitorServiceEvent.java new file mode 100644 index 0000000..a3abcdc --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/MonitorServiceEvent.java @@ -0,0 +1,697 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class MonitorServiceEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("MonitorServiceEvent"); + + private static final org.apache.thrift.protocol.TField V_FIELD_DESC = new org.apache.thrift.protocol.TField("v", org.apache.thrift.protocol.TType.I16, (short)1); + private static final org.apache.thrift.protocol.TField SERVICE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceId", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField SERVICE_URL_FIELD_DESC = new org.apache.thrift.protocol.TField("serviceUrl", org.apache.thrift.protocol.TType.STRING, (short)3); + private static final org.apache.thrift.protocol.TField TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("type", org.apache.thrift.protocol.TType.I32, (short)4); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new MonitorServiceEventStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new MonitorServiceEventTupleSchemeFactory(); + + public short v; // optional + public @org.apache.thrift.annotation.Nullable java.lang.String serviceId; // required + public @org.apache.thrift.annotation.Nullable java.lang.String serviceUrl; // required + /** + * + * @see InfoEventType + */ + public @org.apache.thrift.annotation.Nullable InfoEventType type; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + V((short)1, "v"), + SERVICE_ID((short)2, "serviceId"), + SERVICE_URL((short)3, "serviceUrl"), + /** + * + * @see InfoEventType + */ + TYPE((short)4, "type"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // V + return V; + case 2: // SERVICE_ID + return SERVICE_ID; + case 3: // SERVICE_URL + return SERVICE_URL; + case 4: // TYPE + return TYPE; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __V_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.V}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.V, new org.apache.thrift.meta_data.FieldMetaData("v", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); + tmpMap.put(_Fields.SERVICE_ID, new org.apache.thrift.meta_data.FieldMetaData("serviceId", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.SERVICE_URL, new org.apache.thrift.meta_data.FieldMetaData("serviceUrl", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.TYPE, new org.apache.thrift.meta_data.FieldMetaData("type", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.EnumMetaData(org.apache.thrift.protocol.TType.ENUM, InfoEventType.class))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(MonitorServiceEvent.class, metaDataMap); + } + + public MonitorServiceEvent() { + this.v = (short)1; + + } + + public MonitorServiceEvent( + java.lang.String serviceId, + java.lang.String serviceUrl, + InfoEventType type) + { + this(); + this.serviceId = serviceId; + this.serviceUrl = serviceUrl; + this.type = type; + } + + /** + * Performs a deep copy on other. + */ + public MonitorServiceEvent(MonitorServiceEvent other) { + __isset_bitfield = other.__isset_bitfield; + this.v = other.v; + if (other.isSetServiceId()) { + this.serviceId = other.serviceId; + } + if (other.isSetServiceUrl()) { + this.serviceUrl = other.serviceUrl; + } + if (other.isSetType()) { + this.type = other.type; + } + } + + public MonitorServiceEvent deepCopy() { + return new MonitorServiceEvent(this); + } + + @Override + public void clear() { + this.v = (short)1; + + this.serviceId = null; + this.serviceUrl = null; + this.type = null; + } + + public short getV() { + return this.v; + } + + public MonitorServiceEvent setV(short v) { + this.v = v; + setVIsSet(true); + return this; + } + + public void unsetV() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __V_ISSET_ID); + } + + /** Returns true if field v is set (has been assigned a value) and false otherwise */ + public boolean isSetV() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __V_ISSET_ID); + } + + public void setVIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __V_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getServiceId() { + return this.serviceId; + } + + public MonitorServiceEvent setServiceId(@org.apache.thrift.annotation.Nullable java.lang.String serviceId) { + this.serviceId = serviceId; + return this; + } + + public void unsetServiceId() { + this.serviceId = null; + } + + /** Returns true if field serviceId is set (has been assigned a value) and false otherwise */ + public boolean isSetServiceId() { + return this.serviceId != null; + } + + public void setServiceIdIsSet(boolean value) { + if (!value) { + this.serviceId = null; + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getServiceUrl() { + return this.serviceUrl; + } + + public MonitorServiceEvent setServiceUrl(@org.apache.thrift.annotation.Nullable java.lang.String serviceUrl) { + this.serviceUrl = serviceUrl; + return this; + } + + public void unsetServiceUrl() { + this.serviceUrl = null; + } + + /** Returns true if field serviceUrl is set (has been assigned a value) and false otherwise */ + public boolean isSetServiceUrl() { + return this.serviceUrl != null; + } + + public void setServiceUrlIsSet(boolean value) { + if (!value) { + this.serviceUrl = null; + } + } + + /** + * + * @see InfoEventType + */ + @org.apache.thrift.annotation.Nullable + public InfoEventType getType() { + return this.type; + } + + /** + * + * @see InfoEventType + */ + public MonitorServiceEvent setType(@org.apache.thrift.annotation.Nullable InfoEventType type) { + this.type = type; + return this; + } + + public void unsetType() { + this.type = null; + } + + /** Returns true if field type is set (has been assigned a value) and false otherwise */ + public boolean isSetType() { + return this.type != null; + } + + public void setTypeIsSet(boolean value) { + if (!value) { + this.type = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case V: + if (value == null) { + unsetV(); + } else { + setV((java.lang.Short)value); + } + break; + + case SERVICE_ID: + if (value == null) { + unsetServiceId(); + } else { + setServiceId((java.lang.String)value); + } + break; + + case SERVICE_URL: + if (value == null) { + unsetServiceUrl(); + } else { + setServiceUrl((java.lang.String)value); + } + break; + + case TYPE: + if (value == null) { + unsetType(); + } else { + setType((InfoEventType)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case V: + return getV(); + + case SERVICE_ID: + return getServiceId(); + + case SERVICE_URL: + return getServiceUrl(); + + case TYPE: + return getType(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case V: + return isSetV(); + case SERVICE_ID: + return isSetServiceId(); + case SERVICE_URL: + return isSetServiceUrl(); + case TYPE: + return isSetType(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof MonitorServiceEvent) + return this.equals((MonitorServiceEvent)that); + return false; + } + + public boolean equals(MonitorServiceEvent that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_v = true && this.isSetV(); + boolean that_present_v = true && that.isSetV(); + if (this_present_v || that_present_v) { + if (!(this_present_v && that_present_v)) + return false; + if (this.v != that.v) + return false; + } + + boolean this_present_serviceId = true && this.isSetServiceId(); + boolean that_present_serviceId = true && that.isSetServiceId(); + if (this_present_serviceId || that_present_serviceId) { + if (!(this_present_serviceId && that_present_serviceId)) + return false; + if (!this.serviceId.equals(that.serviceId)) + return false; + } + + boolean this_present_serviceUrl = true && this.isSetServiceUrl(); + boolean that_present_serviceUrl = true && that.isSetServiceUrl(); + if (this_present_serviceUrl || that_present_serviceUrl) { + if (!(this_present_serviceUrl && that_present_serviceUrl)) + return false; + if (!this.serviceUrl.equals(that.serviceUrl)) + return false; + } + + boolean this_present_type = true && this.isSetType(); + boolean that_present_type = true && that.isSetType(); + if (this_present_type || that_present_type) { + if (!(this_present_type && that_present_type)) + return false; + if (!this.type.equals(that.type)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetV()) ? 131071 : 524287); + if (isSetV()) + hashCode = hashCode * 8191 + v; + + hashCode = hashCode * 8191 + ((isSetServiceId()) ? 131071 : 524287); + if (isSetServiceId()) + hashCode = hashCode * 8191 + serviceId.hashCode(); + + hashCode = hashCode * 8191 + ((isSetServiceUrl()) ? 131071 : 524287); + if (isSetServiceUrl()) + hashCode = hashCode * 8191 + serviceUrl.hashCode(); + + hashCode = hashCode * 8191 + ((isSetType()) ? 131071 : 524287); + if (isSetType()) + hashCode = hashCode * 8191 + type.getValue(); + + return hashCode; + } + + @Override + public int compareTo(MonitorServiceEvent other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetV()).compareTo(other.isSetV()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetV()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.v, other.v); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetServiceId()).compareTo(other.isSetServiceId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetServiceId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceId, other.serviceId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetServiceUrl()).compareTo(other.isSetServiceUrl()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetServiceUrl()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.serviceUrl, other.serviceUrl); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetType()).compareTo(other.isSetType()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetType()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.type, other.type); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("MonitorServiceEvent("); + boolean first = true; + + if (isSetV()) { + sb.append("v:"); + sb.append(this.v); + first = false; + } + if (!first) sb.append(", "); + sb.append("serviceId:"); + if (this.serviceId == null) { + sb.append("null"); + } else { + sb.append(this.serviceId); + } + first = false; + if (!first) sb.append(", "); + sb.append("serviceUrl:"); + if (this.serviceUrl == null) { + sb.append("null"); + } else { + sb.append(this.serviceUrl); + } + first = false; + if (!first) sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (serviceId == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'serviceId' was not present! Struct: " + toString()); + } + if (serviceUrl == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'serviceUrl' was not present! Struct: " + toString()); + } + if (type == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'type' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class MonitorServiceEventStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public MonitorServiceEventStandardScheme getScheme() { + return new MonitorServiceEventStandardScheme(); + } + } + + private static class MonitorServiceEventStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, MonitorServiceEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // V + if (schemeField.type == org.apache.thrift.protocol.TType.I16) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // SERVICE_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.serviceId = iprot.readString(); + struct.setServiceIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // SERVICE_URL + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.serviceUrl = iprot.readString(); + struct.setServiceUrlIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 4: // TYPE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.type = com.chriniko.pollfish.thrift.server.protocol.InfoEventType.findByValue(iprot.readI32()); + struct.setTypeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, MonitorServiceEvent struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetV()) { + oprot.writeFieldBegin(V_FIELD_DESC); + oprot.writeI16(struct.v); + oprot.writeFieldEnd(); + } + if (struct.serviceId != null) { + oprot.writeFieldBegin(SERVICE_ID_FIELD_DESC); + oprot.writeString(struct.serviceId); + oprot.writeFieldEnd(); + } + if (struct.serviceUrl != null) { + oprot.writeFieldBegin(SERVICE_URL_FIELD_DESC); + oprot.writeString(struct.serviceUrl); + oprot.writeFieldEnd(); + } + if (struct.type != null) { + oprot.writeFieldBegin(TYPE_FIELD_DESC); + oprot.writeI32(struct.type.getValue()); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class MonitorServiceEventTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public MonitorServiceEventTupleScheme getScheme() { + return new MonitorServiceEventTupleScheme(); + } + } + + private static class MonitorServiceEventTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, MonitorServiceEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.serviceId); + oprot.writeString(struct.serviceUrl); + oprot.writeI32(struct.type.getValue()); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetV()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetV()) { + oprot.writeI16(struct.v); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, MonitorServiceEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.serviceId = iprot.readString(); + struct.setServiceIdIsSet(true); + struct.serviceUrl = iprot.readString(); + struct.setServiceUrlIsSet(true); + struct.type = com.chriniko.pollfish.thrift.server.protocol.InfoEventType.findByValue(iprot.readI32()); + struct.setTypeIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/NotValidInputException.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/NotValidInputException.java new file mode 100644 index 0000000..da48b37 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/NotValidInputException.java @@ -0,0 +1,477 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class NotValidInputException extends org.apache.thrift.TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("NotValidInputException"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField DESCRIPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("description", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new NotValidInputExceptionStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new NotValidInputExceptionTupleSchemeFactory(); + + public int code; // required + public @org.apache.thrift.annotation.Nullable java.lang.String description; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CODE((short)1, "code"), + DESCRIPTION((short)2, "description"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case 2: // DESCRIPTION + return DESCRIPTION; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.CODE, new org.apache.thrift.meta_data.FieldMetaData("code", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); + tmpMap.put(_Fields.DESCRIPTION, new org.apache.thrift.meta_data.FieldMetaData("description", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(NotValidInputException.class, metaDataMap); + } + + public NotValidInputException() { + } + + public NotValidInputException( + int code, + java.lang.String description) + { + this(); + this.code = code; + setCodeIsSet(true); + this.description = description; + } + + /** + * Performs a deep copy on other. + */ + public NotValidInputException(NotValidInputException other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + if (other.isSetDescription()) { + this.description = other.description; + } + } + + public NotValidInputException deepCopy() { + return new NotValidInputException(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + this.description = null; + } + + public int getCode() { + return this.code; + } + + public NotValidInputException setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getDescription() { + return this.description; + } + + public NotValidInputException setDescription(@org.apache.thrift.annotation.Nullable java.lang.String description) { + this.description = description; + return this; + } + + public void unsetDescription() { + this.description = null; + } + + /** Returns true if field description is set (has been assigned a value) and false otherwise */ + public boolean isSetDescription() { + return this.description != null; + } + + public void setDescriptionIsSet(boolean value) { + if (!value) { + this.description = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((java.lang.Integer)value); + } + break; + + case DESCRIPTION: + if (value == null) { + unsetDescription(); + } else { + setDescription((java.lang.String)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case DESCRIPTION: + return getDescription(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case DESCRIPTION: + return isSetDescription(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof NotValidInputException) + return this.equals((NotValidInputException)that); + return false; + } + + public boolean equals(NotValidInputException that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_description = true && this.isSetDescription(); + boolean that_present_description = true && that.isSetDescription(); + if (this_present_description || that_present_description) { + if (!(this_present_description && that_present_description)) + return false; + if (!this.description.equals(that.description)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + code; + + hashCode = hashCode * 8191 + ((isSetDescription()) ? 131071 : 524287); + if (isSetDescription()) + hashCode = hashCode * 8191 + description.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(NotValidInputException other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetCode()).compareTo(other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetDescription()).compareTo(other.isSetDescription()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetDescription()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.description, other.description); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("NotValidInputException("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("description:"); + if (this.description == null) { + sb.append("null"); + } else { + sb.append(this.description); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class NotValidInputExceptionStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public NotValidInputExceptionStandardScheme getScheme() { + return new NotValidInputExceptionStandardScheme(); + } + } + + private static class NotValidInputExceptionStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, NotValidInputException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // DESCRIPTION + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.description = iprot.readString(); + struct.setDescriptionIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, NotValidInputException struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(CODE_FIELD_DESC); + oprot.writeI32(struct.code); + oprot.writeFieldEnd(); + if (struct.description != null) { + oprot.writeFieldBegin(DESCRIPTION_FIELD_DESC); + oprot.writeString(struct.description); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class NotValidInputExceptionTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public NotValidInputExceptionTupleScheme getScheme() { + return new NotValidInputExceptionTupleScheme(); + } + } + + private static class NotValidInputExceptionTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, NotValidInputException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetDescription()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetCode()) { + oprot.writeI32(struct.code); + } + if (struct.isSetDescription()) { + oprot.writeString(struct.description); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, NotValidInputException struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + java.util.BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.description = iprot.readString(); + struct.setDescriptionIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/TransactionEvent.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/TransactionEvent.java new file mode 100644 index 0000000..21805d5 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/TransactionEvent.java @@ -0,0 +1,774 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class TransactionEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("TransactionEvent"); + + private static final org.apache.thrift.protocol.TField V_FIELD_DESC = new org.apache.thrift.protocol.TField("v", org.apache.thrift.protocol.TType.I16, (short)1); + private static final org.apache.thrift.protocol.TField TX_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("txId", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField FROM_ACCOUNT_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("fromAccountId", org.apache.thrift.protocol.TType.STRING, (short)3); + private static final org.apache.thrift.protocol.TField TO_ACCOUNT_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("toAccountId", org.apache.thrift.protocol.TType.STRING, (short)4); + private static final org.apache.thrift.protocol.TField AMOUNT_FIELD_DESC = new org.apache.thrift.protocol.TField("amount", org.apache.thrift.protocol.TType.DOUBLE, (short)5); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new TransactionEventStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new TransactionEventTupleSchemeFactory(); + + public short v; // optional + public @org.apache.thrift.annotation.Nullable java.lang.String txId; // required + public @org.apache.thrift.annotation.Nullable java.lang.String fromAccountId; // required + public @org.apache.thrift.annotation.Nullable java.lang.String toAccountId; // required + public double amount; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + V((short)1, "v"), + TX_ID((short)2, "txId"), + FROM_ACCOUNT_ID((short)3, "fromAccountId"), + TO_ACCOUNT_ID((short)4, "toAccountId"), + AMOUNT((short)5, "amount"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // V + return V; + case 2: // TX_ID + return TX_ID; + case 3: // FROM_ACCOUNT_ID + return FROM_ACCOUNT_ID; + case 4: // TO_ACCOUNT_ID + return TO_ACCOUNT_ID; + case 5: // AMOUNT + return AMOUNT; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __V_ISSET_ID = 0; + private static final int __AMOUNT_ISSET_ID = 1; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.V}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.V, new org.apache.thrift.meta_data.FieldMetaData("v", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); + tmpMap.put(_Fields.TX_ID, new org.apache.thrift.meta_data.FieldMetaData("txId", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.FROM_ACCOUNT_ID, new org.apache.thrift.meta_data.FieldMetaData("fromAccountId", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.TO_ACCOUNT_ID, new org.apache.thrift.meta_data.FieldMetaData("toAccountId", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.AMOUNT, new org.apache.thrift.meta_data.FieldMetaData("amount", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.DOUBLE))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(TransactionEvent.class, metaDataMap); + } + + public TransactionEvent() { + this.v = (short)1; + + } + + public TransactionEvent( + java.lang.String txId, + java.lang.String fromAccountId, + java.lang.String toAccountId, + double amount) + { + this(); + this.txId = txId; + this.fromAccountId = fromAccountId; + this.toAccountId = toAccountId; + this.amount = amount; + setAmountIsSet(true); + } + + /** + * Performs a deep copy on other. + */ + public TransactionEvent(TransactionEvent other) { + __isset_bitfield = other.__isset_bitfield; + this.v = other.v; + if (other.isSetTxId()) { + this.txId = other.txId; + } + if (other.isSetFromAccountId()) { + this.fromAccountId = other.fromAccountId; + } + if (other.isSetToAccountId()) { + this.toAccountId = other.toAccountId; + } + this.amount = other.amount; + } + + public TransactionEvent deepCopy() { + return new TransactionEvent(this); + } + + @Override + public void clear() { + this.v = (short)1; + + this.txId = null; + this.fromAccountId = null; + this.toAccountId = null; + setAmountIsSet(false); + this.amount = 0.0; + } + + public short getV() { + return this.v; + } + + public TransactionEvent setV(short v) { + this.v = v; + setVIsSet(true); + return this; + } + + public void unsetV() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __V_ISSET_ID); + } + + /** Returns true if field v is set (has been assigned a value) and false otherwise */ + public boolean isSetV() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __V_ISSET_ID); + } + + public void setVIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __V_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getTxId() { + return this.txId; + } + + public TransactionEvent setTxId(@org.apache.thrift.annotation.Nullable java.lang.String txId) { + this.txId = txId; + return this; + } + + public void unsetTxId() { + this.txId = null; + } + + /** Returns true if field txId is set (has been assigned a value) and false otherwise */ + public boolean isSetTxId() { + return this.txId != null; + } + + public void setTxIdIsSet(boolean value) { + if (!value) { + this.txId = null; + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getFromAccountId() { + return this.fromAccountId; + } + + public TransactionEvent setFromAccountId(@org.apache.thrift.annotation.Nullable java.lang.String fromAccountId) { + this.fromAccountId = fromAccountId; + return this; + } + + public void unsetFromAccountId() { + this.fromAccountId = null; + } + + /** Returns true if field fromAccountId is set (has been assigned a value) and false otherwise */ + public boolean isSetFromAccountId() { + return this.fromAccountId != null; + } + + public void setFromAccountIdIsSet(boolean value) { + if (!value) { + this.fromAccountId = null; + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getToAccountId() { + return this.toAccountId; + } + + public TransactionEvent setToAccountId(@org.apache.thrift.annotation.Nullable java.lang.String toAccountId) { + this.toAccountId = toAccountId; + return this; + } + + public void unsetToAccountId() { + this.toAccountId = null; + } + + /** Returns true if field toAccountId is set (has been assigned a value) and false otherwise */ + public boolean isSetToAccountId() { + return this.toAccountId != null; + } + + public void setToAccountIdIsSet(boolean value) { + if (!value) { + this.toAccountId = null; + } + } + + public double getAmount() { + return this.amount; + } + + public TransactionEvent setAmount(double amount) { + this.amount = amount; + setAmountIsSet(true); + return this; + } + + public void unsetAmount() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __AMOUNT_ISSET_ID); + } + + /** Returns true if field amount is set (has been assigned a value) and false otherwise */ + public boolean isSetAmount() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __AMOUNT_ISSET_ID); + } + + public void setAmountIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __AMOUNT_ISSET_ID, value); + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case V: + if (value == null) { + unsetV(); + } else { + setV((java.lang.Short)value); + } + break; + + case TX_ID: + if (value == null) { + unsetTxId(); + } else { + setTxId((java.lang.String)value); + } + break; + + case FROM_ACCOUNT_ID: + if (value == null) { + unsetFromAccountId(); + } else { + setFromAccountId((java.lang.String)value); + } + break; + + case TO_ACCOUNT_ID: + if (value == null) { + unsetToAccountId(); + } else { + setToAccountId((java.lang.String)value); + } + break; + + case AMOUNT: + if (value == null) { + unsetAmount(); + } else { + setAmount((java.lang.Double)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case V: + return getV(); + + case TX_ID: + return getTxId(); + + case FROM_ACCOUNT_ID: + return getFromAccountId(); + + case TO_ACCOUNT_ID: + return getToAccountId(); + + case AMOUNT: + return getAmount(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case V: + return isSetV(); + case TX_ID: + return isSetTxId(); + case FROM_ACCOUNT_ID: + return isSetFromAccountId(); + case TO_ACCOUNT_ID: + return isSetToAccountId(); + case AMOUNT: + return isSetAmount(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof TransactionEvent) + return this.equals((TransactionEvent)that); + return false; + } + + public boolean equals(TransactionEvent that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_v = true && this.isSetV(); + boolean that_present_v = true && that.isSetV(); + if (this_present_v || that_present_v) { + if (!(this_present_v && that_present_v)) + return false; + if (this.v != that.v) + return false; + } + + boolean this_present_txId = true && this.isSetTxId(); + boolean that_present_txId = true && that.isSetTxId(); + if (this_present_txId || that_present_txId) { + if (!(this_present_txId && that_present_txId)) + return false; + if (!this.txId.equals(that.txId)) + return false; + } + + boolean this_present_fromAccountId = true && this.isSetFromAccountId(); + boolean that_present_fromAccountId = true && that.isSetFromAccountId(); + if (this_present_fromAccountId || that_present_fromAccountId) { + if (!(this_present_fromAccountId && that_present_fromAccountId)) + return false; + if (!this.fromAccountId.equals(that.fromAccountId)) + return false; + } + + boolean this_present_toAccountId = true && this.isSetToAccountId(); + boolean that_present_toAccountId = true && that.isSetToAccountId(); + if (this_present_toAccountId || that_present_toAccountId) { + if (!(this_present_toAccountId && that_present_toAccountId)) + return false; + if (!this.toAccountId.equals(that.toAccountId)) + return false; + } + + boolean this_present_amount = true; + boolean that_present_amount = true; + if (this_present_amount || that_present_amount) { + if (!(this_present_amount && that_present_amount)) + return false; + if (this.amount != that.amount) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetV()) ? 131071 : 524287); + if (isSetV()) + hashCode = hashCode * 8191 + v; + + hashCode = hashCode * 8191 + ((isSetTxId()) ? 131071 : 524287); + if (isSetTxId()) + hashCode = hashCode * 8191 + txId.hashCode(); + + hashCode = hashCode * 8191 + ((isSetFromAccountId()) ? 131071 : 524287); + if (isSetFromAccountId()) + hashCode = hashCode * 8191 + fromAccountId.hashCode(); + + hashCode = hashCode * 8191 + ((isSetToAccountId()) ? 131071 : 524287); + if (isSetToAccountId()) + hashCode = hashCode * 8191 + toAccountId.hashCode(); + + hashCode = hashCode * 8191 + org.apache.thrift.TBaseHelper.hashCode(amount); + + return hashCode; + } + + @Override + public int compareTo(TransactionEvent other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetV()).compareTo(other.isSetV()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetV()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.v, other.v); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetTxId()).compareTo(other.isSetTxId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetTxId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.txId, other.txId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetFromAccountId()).compareTo(other.isSetFromAccountId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetFromAccountId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.fromAccountId, other.fromAccountId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetToAccountId()).compareTo(other.isSetToAccountId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetToAccountId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.toAccountId, other.toAccountId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetAmount()).compareTo(other.isSetAmount()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetAmount()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.amount, other.amount); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("TransactionEvent("); + boolean first = true; + + if (isSetV()) { + sb.append("v:"); + sb.append(this.v); + first = false; + } + if (!first) sb.append(", "); + sb.append("txId:"); + if (this.txId == null) { + sb.append("null"); + } else { + sb.append(this.txId); + } + first = false; + if (!first) sb.append(", "); + sb.append("fromAccountId:"); + if (this.fromAccountId == null) { + sb.append("null"); + } else { + sb.append(this.fromAccountId); + } + first = false; + if (!first) sb.append(", "); + sb.append("toAccountId:"); + if (this.toAccountId == null) { + sb.append("null"); + } else { + sb.append(this.toAccountId); + } + first = false; + if (!first) sb.append(", "); + sb.append("amount:"); + sb.append(this.amount); + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (txId == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'txId' was not present! Struct: " + toString()); + } + if (fromAccountId == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'fromAccountId' was not present! Struct: " + toString()); + } + if (toAccountId == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'toAccountId' was not present! Struct: " + toString()); + } + // alas, we cannot check 'amount' because it's a primitive and you chose the non-beans generator. + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class TransactionEventStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public TransactionEventStandardScheme getScheme() { + return new TransactionEventStandardScheme(); + } + } + + private static class TransactionEventStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, TransactionEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // V + if (schemeField.type == org.apache.thrift.protocol.TType.I16) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // TX_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.txId = iprot.readString(); + struct.setTxIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // FROM_ACCOUNT_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.fromAccountId = iprot.readString(); + struct.setFromAccountIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 4: // TO_ACCOUNT_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.toAccountId = iprot.readString(); + struct.setToAccountIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 5: // AMOUNT + if (schemeField.type == org.apache.thrift.protocol.TType.DOUBLE) { + struct.amount = iprot.readDouble(); + struct.setAmountIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + if (!struct.isSetAmount()) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'amount' was not found in serialized data! Struct: " + toString()); + } + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, TransactionEvent struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetV()) { + oprot.writeFieldBegin(V_FIELD_DESC); + oprot.writeI16(struct.v); + oprot.writeFieldEnd(); + } + if (struct.txId != null) { + oprot.writeFieldBegin(TX_ID_FIELD_DESC); + oprot.writeString(struct.txId); + oprot.writeFieldEnd(); + } + if (struct.fromAccountId != null) { + oprot.writeFieldBegin(FROM_ACCOUNT_ID_FIELD_DESC); + oprot.writeString(struct.fromAccountId); + oprot.writeFieldEnd(); + } + if (struct.toAccountId != null) { + oprot.writeFieldBegin(TO_ACCOUNT_ID_FIELD_DESC); + oprot.writeString(struct.toAccountId); + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(AMOUNT_FIELD_DESC); + oprot.writeDouble(struct.amount); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class TransactionEventTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public TransactionEventTupleScheme getScheme() { + return new TransactionEventTupleScheme(); + } + } + + private static class TransactionEventTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, TransactionEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.txId); + oprot.writeString(struct.fromAccountId); + oprot.writeString(struct.toAccountId); + oprot.writeDouble(struct.amount); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetV()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetV()) { + oprot.writeI16(struct.v); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, TransactionEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.txId = iprot.readString(); + struct.setTxIdIsSet(true); + struct.fromAccountId = iprot.readString(); + struct.setFromAccountIdIsSet(true); + struct.toAccountId = iprot.readString(); + struct.setToAccountIdIsSet(true); + struct.amount = iprot.readDouble(); + struct.setAmountIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEvent.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEvent.java new file mode 100644 index 0000000..d45801d --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEvent.java @@ -0,0 +1,582 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class UserInfoEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("UserInfoEvent"); + + private static final org.apache.thrift.protocol.TField V_FIELD_DESC = new org.apache.thrift.protocol.TField("v", org.apache.thrift.protocol.TType.I16, (short)1); + private static final org.apache.thrift.protocol.TField USER_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("userId", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField TYPE_FIELD_DESC = new org.apache.thrift.protocol.TField("type", org.apache.thrift.protocol.TType.STRUCT, (short)3); + + private static final org.apache.thrift.scheme.SchemeFactory STANDARD_SCHEME_FACTORY = new UserInfoEventStandardSchemeFactory(); + private static final org.apache.thrift.scheme.SchemeFactory TUPLE_SCHEME_FACTORY = new UserInfoEventTupleSchemeFactory(); + + public short v; // optional + public @org.apache.thrift.annotation.Nullable java.lang.String userId; // required + public @org.apache.thrift.annotation.Nullable UserInfoEventType type; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + V((short)1, "v"), + USER_ID((short)2, "userId"), + TYPE((short)3, "type"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // V + return V; + case 2: // USER_ID + return USER_ID; + case 3: // TYPE + return TYPE; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __V_ISSET_ID = 0; + private byte __isset_bitfield = 0; + private static final _Fields optionals[] = {_Fields.V}; + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.V, new org.apache.thrift.meta_data.FieldMetaData("v", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); + tmpMap.put(_Fields.USER_ID, new org.apache.thrift.meta_data.FieldMetaData("userId", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.TYPE, new org.apache.thrift.meta_data.FieldMetaData("type", org.apache.thrift.TFieldRequirementType.REQUIRED, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "UserInfoEventType"))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(UserInfoEvent.class, metaDataMap); + } + + public UserInfoEvent() { + this.v = (short)1; + + } + + public UserInfoEvent( + java.lang.String userId, + UserInfoEventType type) + { + this(); + this.userId = userId; + this.type = type; + } + + /** + * Performs a deep copy on other. + */ + public UserInfoEvent(UserInfoEvent other) { + __isset_bitfield = other.__isset_bitfield; + this.v = other.v; + if (other.isSetUserId()) { + this.userId = other.userId; + } + if (other.isSetType()) { + this.type = new UserInfoEventType(other.type); + } + } + + public UserInfoEvent deepCopy() { + return new UserInfoEvent(this); + } + + @Override + public void clear() { + this.v = (short)1; + + this.userId = null; + this.type = null; + } + + public short getV() { + return this.v; + } + + public UserInfoEvent setV(short v) { + this.v = v; + setVIsSet(true); + return this; + } + + public void unsetV() { + __isset_bitfield = org.apache.thrift.EncodingUtils.clearBit(__isset_bitfield, __V_ISSET_ID); + } + + /** Returns true if field v is set (has been assigned a value) and false otherwise */ + public boolean isSetV() { + return org.apache.thrift.EncodingUtils.testBit(__isset_bitfield, __V_ISSET_ID); + } + + public void setVIsSet(boolean value) { + __isset_bitfield = org.apache.thrift.EncodingUtils.setBit(__isset_bitfield, __V_ISSET_ID, value); + } + + @org.apache.thrift.annotation.Nullable + public java.lang.String getUserId() { + return this.userId; + } + + public UserInfoEvent setUserId(@org.apache.thrift.annotation.Nullable java.lang.String userId) { + this.userId = userId; + return this; + } + + public void unsetUserId() { + this.userId = null; + } + + /** Returns true if field userId is set (has been assigned a value) and false otherwise */ + public boolean isSetUserId() { + return this.userId != null; + } + + public void setUserIdIsSet(boolean value) { + if (!value) { + this.userId = null; + } + } + + @org.apache.thrift.annotation.Nullable + public UserInfoEventType getType() { + return this.type; + } + + public UserInfoEvent setType(@org.apache.thrift.annotation.Nullable UserInfoEventType type) { + this.type = type; + return this; + } + + public void unsetType() { + this.type = null; + } + + /** Returns true if field type is set (has been assigned a value) and false otherwise */ + public boolean isSetType() { + return this.type != null; + } + + public void setTypeIsSet(boolean value) { + if (!value) { + this.type = null; + } + } + + public void setFieldValue(_Fields field, @org.apache.thrift.annotation.Nullable java.lang.Object value) { + switch (field) { + case V: + if (value == null) { + unsetV(); + } else { + setV((java.lang.Short)value); + } + break; + + case USER_ID: + if (value == null) { + unsetUserId(); + } else { + setUserId((java.lang.String)value); + } + break; + + case TYPE: + if (value == null) { + unsetType(); + } else { + setType((UserInfoEventType)value); + } + break; + + } + } + + @org.apache.thrift.annotation.Nullable + public java.lang.Object getFieldValue(_Fields field) { + switch (field) { + case V: + return getV(); + + case USER_ID: + return getUserId(); + + case TYPE: + return getType(); + + } + throw new java.lang.IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new java.lang.IllegalArgumentException(); + } + + switch (field) { + case V: + return isSetV(); + case USER_ID: + return isSetUserId(); + case TYPE: + return isSetType(); + } + throw new java.lang.IllegalStateException(); + } + + @Override + public boolean equals(java.lang.Object that) { + if (that == null) + return false; + if (that instanceof UserInfoEvent) + return this.equals((UserInfoEvent)that); + return false; + } + + public boolean equals(UserInfoEvent that) { + if (that == null) + return false; + if (this == that) + return true; + + boolean this_present_v = true && this.isSetV(); + boolean that_present_v = true && that.isSetV(); + if (this_present_v || that_present_v) { + if (!(this_present_v && that_present_v)) + return false; + if (this.v != that.v) + return false; + } + + boolean this_present_userId = true && this.isSetUserId(); + boolean that_present_userId = true && that.isSetUserId(); + if (this_present_userId || that_present_userId) { + if (!(this_present_userId && that_present_userId)) + return false; + if (!this.userId.equals(that.userId)) + return false; + } + + boolean this_present_type = true && this.isSetType(); + boolean that_present_type = true && that.isSetType(); + if (this_present_type || that_present_type) { + if (!(this_present_type && that_present_type)) + return false; + if (!this.type.equals(that.type)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + int hashCode = 1; + + hashCode = hashCode * 8191 + ((isSetV()) ? 131071 : 524287); + if (isSetV()) + hashCode = hashCode * 8191 + v; + + hashCode = hashCode * 8191 + ((isSetUserId()) ? 131071 : 524287); + if (isSetUserId()) + hashCode = hashCode * 8191 + userId.hashCode(); + + hashCode = hashCode * 8191 + ((isSetType()) ? 131071 : 524287); + if (isSetType()) + hashCode = hashCode * 8191 + type.hashCode(); + + return hashCode; + } + + @Override + public int compareTo(UserInfoEvent other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = java.lang.Boolean.valueOf(isSetV()).compareTo(other.isSetV()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetV()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.v, other.v); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetUserId()).compareTo(other.isSetUserId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetUserId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.userId, other.userId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = java.lang.Boolean.valueOf(isSetType()).compareTo(other.isSetType()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetType()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.type, other.type); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + scheme(iprot).read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + scheme(oprot).write(oprot, this); + } + + @Override + public java.lang.String toString() { + java.lang.StringBuilder sb = new java.lang.StringBuilder("UserInfoEvent("); + boolean first = true; + + if (isSetV()) { + sb.append("v:"); + sb.append(this.v); + first = false; + } + if (!first) sb.append(", "); + sb.append("userId:"); + if (this.userId == null) { + sb.append("null"); + } else { + sb.append(this.userId); + } + first = false; + if (!first) sb.append(", "); + sb.append("type:"); + if (this.type == null) { + sb.append("null"); + } else { + sb.append(this.type); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + if (userId == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'userId' was not present! Struct: " + toString()); + } + if (type == null) { + throw new org.apache.thrift.protocol.TProtocolException("Required field 'type' was not present! Struct: " + toString()); + } + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class UserInfoEventStandardSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public UserInfoEventStandardScheme getScheme() { + return new UserInfoEventStandardScheme(); + } + } + + private static class UserInfoEventStandardScheme extends org.apache.thrift.scheme.StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, UserInfoEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // V + if (schemeField.type == org.apache.thrift.protocol.TType.I16) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // USER_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.userId = iprot.readString(); + struct.setUserIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 3: // TYPE + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.type = new UserInfoEventType(); + struct.type.read(iprot); + struct.setTypeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, UserInfoEvent struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetV()) { + oprot.writeFieldBegin(V_FIELD_DESC); + oprot.writeI16(struct.v); + oprot.writeFieldEnd(); + } + if (struct.userId != null) { + oprot.writeFieldBegin(USER_ID_FIELD_DESC); + oprot.writeString(struct.userId); + oprot.writeFieldEnd(); + } + if (struct.type != null) { + oprot.writeFieldBegin(TYPE_FIELD_DESC); + struct.type.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class UserInfoEventTupleSchemeFactory implements org.apache.thrift.scheme.SchemeFactory { + public UserInfoEventTupleScheme getScheme() { + return new UserInfoEventTupleScheme(); + } + } + + private static class UserInfoEventTupleScheme extends org.apache.thrift.scheme.TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, UserInfoEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol oprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + oprot.writeString(struct.userId); + struct.type.write(oprot); + java.util.BitSet optionals = new java.util.BitSet(); + if (struct.isSetV()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetV()) { + oprot.writeI16(struct.v); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, UserInfoEvent struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TTupleProtocol iprot = (org.apache.thrift.protocol.TTupleProtocol) prot; + struct.userId = iprot.readString(); + struct.setUserIdIsSet(true); + struct.type = new UserInfoEventType(); + struct.type.read(iprot); + struct.setTypeIsSet(true); + java.util.BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.v = iprot.readI16(); + struct.setVIsSet(true); + } + } + } + + private static S scheme(org.apache.thrift.protocol.TProtocol proto) { + return (org.apache.thrift.scheme.StandardScheme.class.equals(proto.getScheme()) ? STANDARD_SCHEME_FACTORY : TUPLE_SCHEME_FACTORY).getScheme(); + } +} + diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEventType.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEventType.java new file mode 100644 index 0000000..35fe652 --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/protocol/UserInfoEventType.java @@ -0,0 +1,408 @@ +/** + * Autogenerated by Thrift Compiler (0.13.0) + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated + */ +package com.chriniko.pollfish.thrift.server.protocol; + +@SuppressWarnings({"cast", "rawtypes", "serial", "unchecked", "unused"}) +@javax.annotation.Generated(value = "Autogenerated by Thrift Compiler (0.13.0)", date = "2020-11-22") +public class UserInfoEventType extends org.apache.thrift.TUnion { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("UserInfoEventType"); + private static final org.apache.thrift.protocol.TField LOGGED_IN_FIELD_DESC = new org.apache.thrift.protocol.TField("loggedIn", org.apache.thrift.protocol.TType.STRUCT, (short)1); + private static final org.apache.thrift.protocol.TField LOGGED_OUT_FIELD_DESC = new org.apache.thrift.protocol.TField("loggedOut", org.apache.thrift.protocol.TType.STRUCT, (short)2); + private static final org.apache.thrift.protocol.TField CLICKED_ON_ADVERTISEMENT_FIELD_DESC = new org.apache.thrift.protocol.TField("clickedOnAdvertisement", org.apache.thrift.protocol.TType.STRUCT, (short)3); + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + LOGGED_IN((short)1, "loggedIn"), + LOGGED_OUT((short)2, "loggedOut"), + CLICKED_ON_ADVERTISEMENT((short)3, "clickedOnAdvertisement"); + + private static final java.util.Map byName = new java.util.HashMap(); + + static { + for (_Fields field : java.util.EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // LOGGED_IN + return LOGGED_IN; + case 2: // LOGGED_OUT + return LOGGED_OUT; + case 3: // CLICKED_ON_ADVERTISEMENT + return CLICKED_ON_ADVERTISEMENT; + 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 java.lang.IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + @org.apache.thrift.annotation.Nullable + public static _Fields findByName(java.lang.String name) { + return byName.get(name); + } + + private final short _thriftId; + private final java.lang.String _fieldName; + + _Fields(short thriftId, java.lang.String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public java.lang.String getFieldName() { + return _fieldName; + } + } + + public static final java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + java.util.Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new java.util.EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.LOGGED_IN, new org.apache.thrift.meta_data.FieldMetaData("loggedIn", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "LoggedIn"))); + tmpMap.put(_Fields.LOGGED_OUT, new org.apache.thrift.meta_data.FieldMetaData("loggedOut", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "LoggedOut"))); + tmpMap.put(_Fields.CLICKED_ON_ADVERTISEMENT, new org.apache.thrift.meta_data.FieldMetaData("clickedOnAdvertisement", org.apache.thrift.TFieldRequirementType.OPTIONAL, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT , "ClickedOnAdvertisement"))); + metaDataMap = java.util.Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(UserInfoEventType.class, metaDataMap); + } + + public UserInfoEventType() { + super(); + } + + public UserInfoEventType(_Fields setField, java.lang.Object value) { + super(setField, value); + } + + public UserInfoEventType(UserInfoEventType other) { + super(other); + } + public UserInfoEventType deepCopy() { + return new UserInfoEventType(this); + } + + public static UserInfoEventType loggedIn(LoggedIn value) { + UserInfoEventType x = new UserInfoEventType(); + x.setLoggedIn(value); + return x; + } + + public static UserInfoEventType loggedOut(LoggedOut value) { + UserInfoEventType x = new UserInfoEventType(); + x.setLoggedOut(value); + return x; + } + + public static UserInfoEventType clickedOnAdvertisement(ClickedOnAdvertisement value) { + UserInfoEventType x = new UserInfoEventType(); + x.setClickedOnAdvertisement(value); + return x; + } + + + @Override + protected void checkType(_Fields setField, java.lang.Object value) throws java.lang.ClassCastException { + switch (setField) { + case LOGGED_IN: + if (value instanceof LoggedIn) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type LoggedIn for field 'loggedIn', but got " + value.getClass().getSimpleName()); + case LOGGED_OUT: + if (value instanceof LoggedOut) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type LoggedOut for field 'loggedOut', but got " + value.getClass().getSimpleName()); + case CLICKED_ON_ADVERTISEMENT: + if (value instanceof ClickedOnAdvertisement) { + break; + } + throw new java.lang.ClassCastException("Was expecting value of type ClickedOnAdvertisement for field 'clickedOnAdvertisement', but got " + value.getClass().getSimpleName()); + default: + throw new java.lang.IllegalArgumentException("Unknown field id " + setField); + } + } + + @Override + protected java.lang.Object standardSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TField field) throws org.apache.thrift.TException { + _Fields setField = _Fields.findByThriftId(field.id); + if (setField != null) { + switch (setField) { + case LOGGED_IN: + if (field.type == LOGGED_IN_FIELD_DESC.type) { + LoggedIn loggedIn; + loggedIn = new LoggedIn(); + loggedIn.read(iprot); + return loggedIn; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + case LOGGED_OUT: + if (field.type == LOGGED_OUT_FIELD_DESC.type) { + LoggedOut loggedOut; + loggedOut = new LoggedOut(); + loggedOut.read(iprot); + return loggedOut; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + case CLICKED_ON_ADVERTISEMENT: + if (field.type == CLICKED_ON_ADVERTISEMENT_FIELD_DESC.type) { + ClickedOnAdvertisement clickedOnAdvertisement; + clickedOnAdvertisement = new ClickedOnAdvertisement(); + clickedOnAdvertisement.read(iprot); + return clickedOnAdvertisement; + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + default: + throw new java.lang.IllegalStateException("setField wasn't null, but didn't match any of the case statements!"); + } + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); + return null; + } + } + + @Override + protected void standardSchemeWriteValue(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + switch (setField_) { + case LOGGED_IN: + LoggedIn loggedIn = (LoggedIn)value_; + loggedIn.write(oprot); + return; + case LOGGED_OUT: + LoggedOut loggedOut = (LoggedOut)value_; + loggedOut.write(oprot); + return; + case CLICKED_ON_ADVERTISEMENT: + ClickedOnAdvertisement clickedOnAdvertisement = (ClickedOnAdvertisement)value_; + clickedOnAdvertisement.write(oprot); + return; + default: + throw new java.lang.IllegalStateException("Cannot write union with unknown field " + setField_); + } + } + + @Override + protected java.lang.Object tupleSchemeReadValue(org.apache.thrift.protocol.TProtocol iprot, short fieldID) throws org.apache.thrift.TException { + _Fields setField = _Fields.findByThriftId(fieldID); + if (setField != null) { + switch (setField) { + case LOGGED_IN: + LoggedIn loggedIn; + loggedIn = new LoggedIn(); + loggedIn.read(iprot); + return loggedIn; + case LOGGED_OUT: + LoggedOut loggedOut; + loggedOut = new LoggedOut(); + loggedOut.read(iprot); + return loggedOut; + case CLICKED_ON_ADVERTISEMENT: + ClickedOnAdvertisement clickedOnAdvertisement; + clickedOnAdvertisement = new ClickedOnAdvertisement(); + clickedOnAdvertisement.read(iprot); + return clickedOnAdvertisement; + default: + throw new java.lang.IllegalStateException("setField wasn't null, but didn't match any of the case statements!"); + } + } else { + throw new org.apache.thrift.protocol.TProtocolException("Couldn't find a field with field id " + fieldID); + } + } + + @Override + protected void tupleSchemeWriteValue(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + switch (setField_) { + case LOGGED_IN: + LoggedIn loggedIn = (LoggedIn)value_; + loggedIn.write(oprot); + return; + case LOGGED_OUT: + LoggedOut loggedOut = (LoggedOut)value_; + loggedOut.write(oprot); + return; + case CLICKED_ON_ADVERTISEMENT: + ClickedOnAdvertisement clickedOnAdvertisement = (ClickedOnAdvertisement)value_; + clickedOnAdvertisement.write(oprot); + return; + default: + throw new java.lang.IllegalStateException("Cannot write union with unknown field " + setField_); + } + } + + @Override + protected org.apache.thrift.protocol.TField getFieldDesc(_Fields setField) { + switch (setField) { + case LOGGED_IN: + return LOGGED_IN_FIELD_DESC; + case LOGGED_OUT: + return LOGGED_OUT_FIELD_DESC; + case CLICKED_ON_ADVERTISEMENT: + return CLICKED_ON_ADVERTISEMENT_FIELD_DESC; + default: + throw new java.lang.IllegalArgumentException("Unknown field id " + setField); + } + } + + @Override + protected org.apache.thrift.protocol.TStruct getStructDesc() { + return STRUCT_DESC; + } + + @Override + protected _Fields enumForId(short id) { + return _Fields.findByThriftIdOrThrow(id); + } + + @org.apache.thrift.annotation.Nullable + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + + public LoggedIn getLoggedIn() { + if (getSetField() == _Fields.LOGGED_IN) { + return (LoggedIn)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'loggedIn' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setLoggedIn(LoggedIn value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.LOGGED_IN; + value_ = value; + } + + public LoggedOut getLoggedOut() { + if (getSetField() == _Fields.LOGGED_OUT) { + return (LoggedOut)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'loggedOut' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setLoggedOut(LoggedOut value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.LOGGED_OUT; + value_ = value; + } + + public ClickedOnAdvertisement getClickedOnAdvertisement() { + if (getSetField() == _Fields.CLICKED_ON_ADVERTISEMENT) { + return (ClickedOnAdvertisement)getFieldValue(); + } else { + throw new java.lang.RuntimeException("Cannot get field 'clickedOnAdvertisement' because union is currently set to " + getFieldDesc(getSetField()).name); + } + } + + public void setClickedOnAdvertisement(ClickedOnAdvertisement value) { + if (value == null) throw new java.lang.NullPointerException(); + setField_ = _Fields.CLICKED_ON_ADVERTISEMENT; + value_ = value; + } + + public boolean isSetLoggedIn() { + return setField_ == _Fields.LOGGED_IN; + } + + + public boolean isSetLoggedOut() { + return setField_ == _Fields.LOGGED_OUT; + } + + + public boolean isSetClickedOnAdvertisement() { + return setField_ == _Fields.CLICKED_ON_ADVERTISEMENT; + } + + + public boolean equals(java.lang.Object other) { + if (other instanceof UserInfoEventType) { + return equals((UserInfoEventType)other); + } else { + return false; + } + } + + public boolean equals(UserInfoEventType other) { + return other != null && getSetField() == other.getSetField() && getFieldValue().equals(other.getFieldValue()); + } + + @Override + public int compareTo(UserInfoEventType other) { + int lastComparison = org.apache.thrift.TBaseHelper.compareTo(getSetField(), other.getSetField()); + if (lastComparison == 0) { + return org.apache.thrift.TBaseHelper.compareTo(getFieldValue(), other.getFieldValue()); + } + return lastComparison; + } + + + @Override + public int hashCode() { + java.util.List list = new java.util.ArrayList(); + list.add(this.getClass().getName()); + org.apache.thrift.TFieldIdEnum setField = getSetField(); + if (setField != null) { + list.add(setField.getThriftFieldId()); + java.lang.Object value = getFieldValue(); + if (value instanceof org.apache.thrift.TEnum) { + list.add(((org.apache.thrift.TEnum)getFieldValue()).getValue()); + } else { + list.add(value); + } + } + return list.hashCode(); + } + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventAsyncServiceImpl.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventAsyncServiceImpl.java new file mode 100644 index 0000000..30d0f5a --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventAsyncServiceImpl.java @@ -0,0 +1,62 @@ +package com.chriniko.pollfish.thrift.server.service; + +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEventService; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEventServiceHealthStatus; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.log4j.Log4j2; +import org.apache.kafka.clients.admin.AdminClient; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.common.utils.Bytes; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; + +import java.util.Set; + +@Log4j2 +public class LoggingEventAsyncServiceImpl implements LoggingEventService.AsyncIface { + + private final LoggingEventServiceImpl delegate; + + public LoggingEventAsyncServiceImpl(Producer producer, ObjectMapper mapper, String topicName, AdminClient adminClient) { + delegate = new LoggingEventServiceImpl(producer, topicName, adminClient, mapper); + } + + @Override + public void save(LoggingEvent evt, AsyncMethodCallback resultHandler) throws TException { + try { + log.debug("async service used for save"); // Note: added, just to check that it is dispatching work to the specified thread pool. + LoggingEvent result = delegate.save(evt); + resultHandler.onComplete(result); + } catch (Exception e) { + log.error("error occurred during save of logging event, msg: " + e.getMessage(), e); + resultHandler.onError(e); + } + } + + @Override + public void batchSave(Set evts, AsyncMethodCallback> resultHandler) throws TException { + try { + log.debug("async service used for batch-save"); // Note: added, just to check that it is dispatching work to the specified thread pool. + Set result = delegate.batchSave(evts); + resultHandler.onComplete(result); + } catch (Exception e) { + log.error("error occurred during save of logging event[batch], msg: " + e.getMessage(), e); + resultHandler.onError(e); + } + } + + @Override + public void healthStatus(AsyncMethodCallback resultHandler) throws TException { + try { + log.debug("async service used for health status"); // Note: added, just to check that it is dispatching work to the specified thread pool. + LoggingEventServiceHealthStatus result = delegate.healthStatus(); + resultHandler.onComplete(result); + } catch (Exception e) { + log.error("error occurred during retrieval of health status, msg: " + e.getMessage(), e); + resultHandler.onError(e); + } + } + + +} diff --git a/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventServiceImpl.java b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventServiceImpl.java new file mode 100644 index 0000000..81f601e --- /dev/null +++ b/thrift-server/src/main/java/com/chriniko/pollfish/thrift/server/service/LoggingEventServiceImpl.java @@ -0,0 +1,111 @@ +package com.chriniko.pollfish.thrift.server.service; + +import com.chriniko.pollfish.thrift.server.error.LoggingServerErrorCodes; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEvent; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEventService; +import com.chriniko.pollfish.thrift.server.protocol.LoggingEventServiceHealthStatus; +import com.chriniko.pollfish.thrift.server.protocol.NotValidInputException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.log4j.Log4j2; +import org.apache.kafka.clients.admin.AdminClient; +import org.apache.kafka.clients.admin.TopicListing; +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.apache.kafka.common.utils.Bytes; +import org.apache.thrift.TException; +import org.apache.thrift.TSerializer; + +import java.time.Instant; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + + +@Log4j2 +public class LoggingEventServiceImpl implements LoggingEventService.Iface { + + private static final int TIME_MS = 1200; + + + private final Producer kafkaProducer; + private final String topic; + private final AdminClient adminClient; + private final ObjectMapper mapper; + + private final ThreadLocal tSerializerThreadLocal = ThreadLocal.withInitial(TSerializer::new); + + public LoggingEventServiceImpl(Producer kafkaProducer, + String topic, AdminClient adminClient, + ObjectMapper mapper) { + this.kafkaProducer = kafkaProducer; + this.topic = topic; + this.adminClient = adminClient; + this.mapper = mapper; + } + + @Override + public LoggingEvent save(LoggingEvent evt) throws TException { + + final byte[] bytes; + try { + bytes = tSerializerThreadLocal.get().serialize(evt); + } catch (Exception e) { + log.error("could not serialize logging event id: " + evt.id + " and origin: " + evt.origin, e); + throw new NotValidInputException(LoggingServerErrorCodes.SERIALIZATION_ERROR.getCode(), e.getMessage()); + } + + + ProducerRecord producerRecord = new ProducerRecord<>(topic, null, Instant.now().toEpochMilli(), + evt.id, Bytes.wrap(bytes) + ); + + try { + RecordMetadata recordMetadata = kafkaProducer.send(producerRecord).get(TIME_MS, TimeUnit.MILLISECONDS); + log.info("logging event sent to infra, recordMetadata: " + recordMetadata); + return evt; + + } catch (InterruptedException e) { + log.error("error occurred during save of logging event, msg: " + e.getMessage(), e); + Thread.currentThread().interrupt(); + throw new TException("save failure" + e.getMessage(), e); + } catch (ExecutionException | TimeoutException e) { + log.error("error occurred during save of logging event, msg: " + e.getMessage(), e); + throw new TException("save failure" + e.getMessage(), e); + } + } + + @Override + public Set batchSave(Set evts) throws TException { + for (LoggingEvent evt : evts) { + save(evt); + } + return evts; + } + + @Override + public LoggingEventServiceHealthStatus healthStatus() throws TException { + try { + final LoggingEventServiceHealthStatus result = new LoggingEventServiceHealthStatus(); + final StringBuilder sb = new StringBuilder(); + + sb.append("==== topic listings ====\n"); + for (TopicListing topicListing : adminClient.listTopics().listings().get(TIME_MS * 3L, TimeUnit.MILLISECONDS)) { + sb.append(topicListing).append("\n"); + } + + sb.append("\n\n"); + + result.setHealthy(sb.length() != 0); + result.setMsg(mapper.writeValueAsBytes(sb.toString())); + + return result; + + } catch (Exception e) { + log.error("error occurred during retrieval of health status, msg: " + e.getMessage(), e); + throw new TException("healthStatus failure: " + e.getMessage(), e); + } + } + +} diff --git a/thrift-server/src/main/java/logging_event_service.thrift b/thrift-server/src/main/java/logging_event_service.thrift new file mode 100644 index 0000000..5ab2bae --- /dev/null +++ b/thrift-server/src/main/java/logging_event_service.thrift @@ -0,0 +1,112 @@ +namespace java com.chriniko.pollfish.thrift.server.protocol + +// ------------------------ message payloads --------------------------------------------------------------------------- + + +enum InfoEventType { + LOW_MEMORY, + CPU_IDLE, + CPU_HOT +} + +struct MonitorServiceEvent { + 1: optional i16 v = 1, // indicates version number + + 2: required string serviceId, + 3: required string serviceUrl, + 4: required InfoEventType type +} + +// ---- + +struct TransactionEvent { + 1: optional i16 v = 1, // indicates version number + + 2: required string txId, + 3: required string fromAccountId, + 4: required string toAccountId, + 5: required double amount +} + +// ---- + +struct UserInfoEvent { + + 1: optional i16 v = 1, // indicates version number + + 2: required string userId, + + 3: required UserInfoEventType type +} + +union UserInfoEventType { + 1: LoggedIn loggedIn, + 2: LoggedOut loggedOut, + 3: ClickedOnAdvertisement clickedOnAdvertisement +} + + +struct LoggedIn { + 1: required string url +} + +struct LoggedOut { + 1: required i64 durationOfLoginInSecs +} + +struct ClickedOnAdvertisement { + 1: required string clickUrl, + 2: required string callbackTracker +} + + +// ------------------------ logging event infra ------------------------------------------------------------------------ + +enum LoggingEventPriority { + NORMAL, + MEDIUM, + CRITICAL +} + +union LoggingEventPayload { + 1: MonitorServiceEvent monitorServiceEvent, + 2: TransactionEvent transactionEvent, + 3: UserInfoEvent userInfoEvent + + // Note: add your new events here. +} + + + struct LoggingEvent { + 1: optional i16 v = 1, // indicates version number + + 2: required string id, // this will be a UUID + 3: required string origin, // which system was the sender of this message + + 4: required i64 time, // it will hold the epoch millis based on the "1970-01-01T00:00:00Z" + + 5: optional map metadata, // headers/metadata + + 6: required LoggingEventPayload m, // message + + 7: optional LoggingEventPriority priority = LoggingEventPriority.NORMAL, + } + + exception NotValidInputException { + 1: i32 code, + 2: string description, + } + + struct LoggingEventServiceHealthStatus { + 1: bool healthy, + 2: binary msg + } + +service LoggingEventService { + + LoggingEvent save(1:LoggingEvent evt) throws (1:NotValidInputException e) + + set batchSave(1: set evts) throws (1:NotValidInputException e) + + LoggingEventServiceHealthStatus healthStatus() +} \ No newline at end of file diff --git a/thrift-server/src/main/resources/application.properties b/thrift-server/src/main/resources/application.properties new file mode 100644 index 0000000..6d92a33 --- /dev/null +++ b/thrift-server/src/main/resources/application.properties @@ -0,0 +1,7 @@ + +kafka-brokers=localhost:19092 +client-id=thriftServerClient +topic-name=log-events + +server-port=9090 +io-intensive-pool.size=200 \ No newline at end of file diff --git a/thrift-server/src/main/resources/log4j2.xml b/thrift-server/src/main/resources/log4j2.xml new file mode 100644 index 0000000..a7512ff --- /dev/null +++ b/thrift-server/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file