Commit 3cb1e103 authored by Natanael BOUTEILLER's avatar Natanael BOUTEILLER
Browse files

GameService.java

parent 21db3ff5
......@@ -7,7 +7,7 @@ struct JoinRequest {
1: string name
}
service GameService {
service GameServerService {
i32 createGame(i32 numberOfPlayers)
......
......@@ -2,7 +2,8 @@ package fr.univnantes.alma.game;
import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.common.GameService;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -13,7 +14,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.atlanmod.commons.Preconditions.checkArgument;
@Component
public class GameController implements GameInterface {
public class GameController implements GameService {
private final AtomicInteger idCounter = new AtomicInteger(0);
private final Map<Integer, Game> games = new HashMap<>();
......
package fr.univnantes.alma.handler;
import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.common.GameService;
import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.thrift.JoinRequest;
import fr.univnantes.alma.thrift.GameNotFound;
import fr.univnantes.alma.thrift.GameServerService;
import fr.univnantes.alma.thrift.JoinRequest;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -12,10 +15,10 @@ import java.util.LinkedList;
import java.util.List;
@Component
public class GameServiceHandler implements GameService.Iface {
public class GameServiceHandler implements GameServerService.Iface {
@Autowired
GameInterface service;
GameService service;
@Override
public int createGame(int numberOfPlayers) throws TException {
......
/* tslint:disable */
/* eslint-disable */
/*
* Autogenerated by @creditkarma/thrift-typescript v3.7.6
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
import * as thrift from "@creditkarma/thrift-server-core";
export interface IGameNotFound {
code?: number;
description?: string;
}
export interface IGameNotFoundArgs {
code?: number;
description?: string;
}
export const GameNotFoundCodec: thrift.IStructCodec<IGameNotFoundArgs, IGameNotFound> = {
encode(args: IGameNotFoundArgs, output: thrift.TProtocol): void {
const obj: any = {
code: args.code,
description: args.description
};
output.writeStructBegin("GameNotFound");
if (obj.code != null) {
output.writeFieldBegin("code", thrift.TType.I32, 1);
output.writeI32(obj.code);
output.writeFieldEnd();
}
if (obj.description != null) {
output.writeFieldBegin("description", thrift.TType.STRING, 2);
output.writeString(obj.description);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
},
decode(input: thrift.TProtocol): IGameNotFound {
let _args: any = {};
input.readStructBegin();
while (true) {
const ret: thrift.IThriftField = input.readFieldBegin();
const fieldType: thrift.TType = ret.fieldType;
const fieldId: number = ret.fieldId;
if (fieldType === thrift.TType.STOP) {
break;
}
switch (fieldId) {
case 1:
if (fieldType === thrift.TType.I32) {
const value_1: number = input.readI32();
_args.code = value_1;
}
else {
input.skip(fieldType);
}
break;
case 2:
if (fieldType === thrift.TType.STRING) {
const value_2: string = input.readString();
_args.description = value_2;
}
else {
input.skip(fieldType);
}
break;
default: {
input.skip(fieldType);
}
}
input.readFieldEnd();
}
input.readStructEnd();
return {
code: _args.code,
description: _args.description
};
}
};
export class GameNotFound extends thrift.StructLike implements IGameNotFound {
public code?: number;
public description?: string;
public readonly _annotations: thrift.IThriftAnnotations = {};
public readonly _fieldAnnotations: thrift.IFieldAnnotations = {};
constructor(args: IGameNotFoundArgs = {}) {
super();
if (args.code != null) {
const value_3: number = args.code;
this.code = value_3;
}
if (args.description != null) {
const value_4: string = args.description;
this.description = value_4;
}
}
public static read(input: thrift.TProtocol): GameNotFound {
return new GameNotFound(GameNotFoundCodec.decode(input));
}
public static write(args: IGameNotFoundArgs, output: thrift.TProtocol): void {
return GameNotFoundCodec.encode(args, output);
}
public write(output: thrift.TProtocol): void {
return GameNotFoundCodec.encode(this, output);
}
}
/* tslint:disable */
/* eslint-disable */
/*
* Autogenerated by @creditkarma/thrift-typescript v3.7.6
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
import * as thrift from "@creditkarma/thrift-server-core";
export interface IInvalidOperationException {
code?: number;
description?: string;
}
export interface IInvalidOperationExceptionArgs {
code?: number;
description?: string;
}
export const InvalidOperationExceptionCodec: thrift.IStructCodec<IInvalidOperationExceptionArgs, IInvalidOperationException> = {
encode(args: IInvalidOperationExceptionArgs, output: thrift.TProtocol): void {
const obj: any = {
code: args.code,
description: args.description
};
output.writeStructBegin("InvalidOperationException");
if (obj.code != null) {
output.writeFieldBegin("code", thrift.TType.I32, 1);
output.writeI32(obj.code);
output.writeFieldEnd();
}
if (obj.description != null) {
output.writeFieldBegin("description", thrift.TType.STRING, 2);
output.writeString(obj.description);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
},
decode(input: thrift.TProtocol): IInvalidOperationException {
let _args: any = {};
input.readStructBegin();
while (true) {
const ret: thrift.IThriftField = input.readFieldBegin();
const fieldType: thrift.TType = ret.fieldType;
const fieldId: number = ret.fieldId;
if (fieldType === thrift.TType.STOP) {
break;
}
switch (fieldId) {
case 1:
if (fieldType === thrift.TType.I32) {
const value_1: number = input.readI32();
_args.code = value_1;
}
else {
input.skip(fieldType);
}
break;
case 2:
if (fieldType === thrift.TType.STRING) {
const value_2: string = input.readString();
_args.description = value_2;
}
else {
input.skip(fieldType);
}
break;
default: {
input.skip(fieldType);
}
}
input.readFieldEnd();
}
input.readStructEnd();
return {
code: _args.code,
description: _args.description
};
}
};
export class InvalidOperationException extends thrift.StructLike implements IInvalidOperationException {
public code?: number;
public description?: string;
public readonly _annotations: thrift.IThriftAnnotations = {};
public readonly _fieldAnnotations: thrift.IFieldAnnotations = {};
constructor(args: IInvalidOperationExceptionArgs = {}) {
super();
if (args.code != null) {
const value_3: number = args.code;
this.code = value_3;
}
if (args.description != null) {
const value_4: string = args.description;
this.description = value_4;
}
}
public static read(input: thrift.TProtocol): InvalidOperationException {
return new InvalidOperationException(InvalidOperationExceptionCodec.decode(input));
}
public static write(args: IInvalidOperationExceptionArgs, output: thrift.TProtocol): void {
return InvalidOperationExceptionCodec.encode(args, output);
}
public write(output: thrift.TProtocol): void {
return InvalidOperationExceptionCodec.encode(this, output);
}
}
/* tslint:disable */
/* eslint-disable */
/*
* Autogenerated by @creditkarma/thrift-typescript v3.7.6
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
export * from "./InvalidOperationException";
export * from "./GameNotFound";
/* tslint:disable */
/* eslint-disable */
/*
* Autogenerated by @creditkarma/thrift-typescript v3.7.6
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
import * as thrift from "@creditkarma/thrift-server-core";
import * as core from "./..\\..\\..\\..\\core";
export const serviceName: string = "GameClientService";
export const annotations: thrift.IThriftAnnotations = {};
export const methodAnnotations: thrift.IMethodAnnotations = {
ping: {
annotations: {},
fieldAnnotations: {}
}
};
export const methodNames: Array<string> = ["ping"];
export const methodParameters: {
[methodName: string]: number;
} = {
ping: 1
};
export interface IPing__Args {
}
export interface IPing__ArgsArgs {
}
export const Ping__ArgsCodec: thrift.IStructCodec<IPing__ArgsArgs, IPing__Args> = {
encode(args: IPing__ArgsArgs, output: thrift.TProtocol): void {
output.writeStructBegin("Ping__Args");
output.writeFieldStop();
output.writeStructEnd();
return;
},
decode(input: thrift.TProtocol): IPing__Args {
input.readStructBegin();
while (true) {
const ret: thrift.IThriftField = input.readFieldBegin();
const fieldType: thrift.TType = ret.fieldType;
const fieldId: number = ret.fieldId;
if (fieldType === thrift.TType.STOP) {
break;
}
switch (fieldId) {
default: {
input.skip(fieldType);
}
}
input.readFieldEnd();
}
input.readStructEnd();
return {};
}
};
export class Ping__Args extends thrift.StructLike implements IPing__Args {
public readonly _annotations: thrift.IThriftAnnotations = {};
public readonly _fieldAnnotations: thrift.IFieldAnnotations = {};
constructor(args: IPing__ArgsArgs = {}) {
super();
}
public static read(input: thrift.TProtocol): Ping__Args {
return new Ping__Args(Ping__ArgsCodec.decode(input));
}
public static write(args: IPing__ArgsArgs, output: thrift.TProtocol): void {
return Ping__ArgsCodec.encode(args, output);
}
public write(output: thrift.TProtocol): void {
return Ping__ArgsCodec.encode(this, output);
}
}
export interface IPing__Result {
success?: boolean;
e?: core.IInvalidOperationException;
}
export interface IPing__ResultArgs {
success?: boolean;
e?: core.IInvalidOperationExceptionArgs;
}
export const Ping__ResultCodec: thrift.IStructCodec<IPing__ResultArgs, IPing__Result> = {
encode(args: IPing__ResultArgs, output: thrift.TProtocol): void {
const obj: any = {
success: args.success,
e: args.e
};
output.writeStructBegin("Ping__Result");
if (obj.success != null) {
output.writeFieldBegin("success", thrift.TType.BOOL, 0);
output.writeBool(obj.success);
output.writeFieldEnd();
}
if (obj.e != null) {
output.writeFieldBegin("e", thrift.TType.STRUCT, 1);
core.InvalidOperationExceptionCodec.encode(obj.e, output);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
},
decode(input: thrift.TProtocol): IPing__Result {
let _args: any = {};
input.readStructBegin();
while (true) {
const ret: thrift.IThriftField = input.readFieldBegin();
const fieldType: thrift.TType = ret.fieldType;
const fieldId: number = ret.fieldId;
if (fieldType === thrift.TType.STOP) {
break;
}
switch (fieldId) {
case 0:
if (fieldType === thrift.TType.BOOL) {
const value_1: boolean = input.readBool();
_args.success = value_1;
}
else {
input.skip(fieldType);
}
break;
case 1:
if (fieldType === thrift.TType.STRUCT) {
const value_2: core.IInvalidOperationException = core.InvalidOperationExceptionCodec.decode(input);
_args.e = value_2;
}
else {
input.skip(fieldType);
}
break;
default: {
input.skip(fieldType);
}
}
input.readFieldEnd();
}
input.readStructEnd();
return {
success: _args.success,
e: _args.e
};
}
};
export class Ping__Result extends thrift.StructLike implements IPing__Result {
public success?: boolean;
public e?: core.IInvalidOperationException;
public readonly _annotations: thrift.IThriftAnnotations = {};
public readonly _fieldAnnotations: thrift.IFieldAnnotations = {};
constructor(args: IPing__ResultArgs = {}) {
super();
if (args.success != null) {
const value_3: boolean = args.success;
this.success = value_3;
}
if (args.e != null) {
const value_4: core.IInvalidOperationException = new core.InvalidOperationException(args.e);
this.e = value_4;
}
}
public static read(input: thrift.TProtocol): Ping__Result {
return new Ping__Result(Ping__ResultCodec.decode(input));
}
public static write(args: IPing__ResultArgs, output: thrift.TProtocol): void {
return Ping__ResultCodec.encode(args, output);
}
public write(output: thrift.TProtocol): void {
return Ping__ResultCodec.encode(this, output);
}
}
export class Client<Context = any> extends thrift.ThriftClient<Context> {
public static readonly serviceName: string = serviceName;
public static readonly annotations: thrift.IThriftAnnotations = annotations;
public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations;
public static readonly methodNames: Array<string> = methodNames;
public readonly _serviceName: string = serviceName;
public readonly _annotations: thrift.IThriftAnnotations = annotations;
public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations;
public readonly _methodNames: Array<string> = methodNames;
public readonly _methodParameters?: {
[methodName: string]: number;
} = methodParameters;
public ping(context?: Context): Promise<boolean> {
const writer: thrift.TTransport = new this.transport();
const output: thrift.TProtocol = new this.protocol(writer);
output.writeMessageBegin("ping", thrift.MessageType.CALL, this.incrementRequestId());
const args: IPing__ArgsArgs = {};
Ping__ArgsCodec.encode(args, output);
output.writeMessageEnd();
return this.connection.send(writer.flush(), context).then((data: Buffer) => {
const reader: thrift.TTransport = this.transport.receiver(data);
const input: thrift.TProtocol = new this.protocol(reader);
try {
const { fieldName: fieldName, messageType: messageType }: thrift.IThriftMessage = input.readMessageBegin();
if (fieldName === "ping") {
if (messageType === thrift.MessageType.EXCEPTION) {
const err: thrift.TApplicationException = thrift.TApplicationExceptionCodec.decode(input);
input.readMessageEnd();
return Promise.reject(err);
}
else {
const result: IPing__Result = Ping__ResultCodec.decode(input);
input.readMessageEnd();
if (result.e != null) {
return Promise.reject(result.e);
}
else if (result.success != null) {
return Promise.resolve(result.success);
}
else {
return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, "ping failed: unknown result"));
}
}
}
else {
return Promise.reject(new thrift.TApplicationException(thrift.TApplicationExceptionType.WRONG_METHOD_NAME, "Received a response to an unknown RPC function: " + fieldName));
}
}
catch (err) {
return Promise.reject(err);
}
});
}
}
export interface IHandler<Context = any> {
ping(context?: Context): boolean | Promise<boolean>;
}
export class Processor<Context = any> extends thrift.ThriftProcessor<Context, IHandler<Context>> {
protected readonly _handler: IHandler<Context>;
public static readonly serviceName: string = serviceName;
public static readonly annotations: thrift.IThriftAnnotations = annotations;
public static readonly methodAnnotations: thrift.IMethodAnnotations = methodAnnotations;
public static readonly methodNames: Array<string> = methodNames;
public readonly _serviceName: string = serviceName;
public readonly _annotations: thrift.IThriftAnnotations = annotations;
public readonly _methodAnnotations: thrift.IMethodAnnotations = methodAnnotations;
public readonly _methodNames: Array<string> = methodNames;
constructor(handler: IHandler<Context>) {
super();
this._handler = handler;
}
public process(input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise<Buffer> {
return new Promise<Buffer>((resolve, reject): void => {
const metadata: thrift.IThriftMessage = input.readMessageBegin();
const fieldName: string = metadata.fieldName;
const requestId: number = metadata.requestId;
const methodName: string = "process_" + fieldName;
switch (methodName) {
case "process_ping": {
resolve(this.process_ping(requestId, input, output, context));
break;
}
default: {
input.skip(thrift.TType.STRUCT);
input.readMessageEnd();
const errMessage = "Unknown function " + fieldName;
const err = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN_METHOD, errMessage);
output.writeMessageBegin(fieldName, thrift.MessageType.EXCEPTION, requestId);
thrift.TApplicationExceptionCodec.encode(err, output);
output.writeMessageEnd();
resolve(output.flush());
break;
}
}
});
}
public process_ping(requestId: number, input: thrift.TProtocol, output: thrift.TProtocol, context: Context): Promise<Buffer> {
return new Promise<boolean>((resolve, reject): void => {
try {
input.readMessageEnd();
resolve(this._handler.ping(context));
}
catch (err) {
reject(err);
}
}).then((data: boolean): Buffer => {
const result: IPing__ResultArgs = { success: data };
output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId);
Ping__ResultCodec.encode(result, output);
output.writeMessageEnd();
return output.flush();
}).catch((err: Error): Buffer => {
if (err instanceof core.InvalidOperationException) {
const result: IPing__ResultArgs = { e: err };
output.writeMessageBegin("ping", thrift.MessageType.REPLY, requestId);
Ping__ResultCodec.encode(result, output);
output.writeMessageEnd();
return output.flush();
}
else {
const result: thrift.TApplicationException = new thrift.TApplicationException(thrift.TApplicationExceptionType.UNKNOWN, err.message);
output.writeMessageBegin("ping", thrift.MessageType.EXCEPTION, requestId);
thrift.TApplicationExceptionCodec.encode(result, output);