Skip to content

Commit

Permalink
Merge pull request mrniko#9 from YoonsooChang/yoonsoo
Browse files Browse the repository at this point in the history
Merge (Merge pull request mrniko#8 from jjhun1856/master to YoonsooChang/yoonsoo) into master branch
  • Loading branch information
YoonsooChang committed May 31, 2020
2 parents 3cc68a9 + 03e819d commit 8b385cb
Show file tree
Hide file tree
Showing 33 changed files with 2,760 additions and 2,755 deletions.
1,178 changes: 591 additions & 587 deletions src/main/java/com/corundumstudio/socketio/Configuration.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import com.corundumstudio.socketio.namespace.Namespace;

public interface AnnotationScanner {

Class<? extends Annotation> getScanAnnotation();

void addListener(Namespace namespace, Object object, Method method, Annotation annotation);

void validate(Method method, Class<?> clazz);

/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import com.corundumstudio.socketio.namespace.Namespace;

public interface AnnotationScanner {

Class<? extends Annotation> getScanAnnotation();

void addListener(Namespace namespace, Object object, Method method, Annotation annotation);

void validateListener(Method method, Class<?> clazz);

}
72 changes: 36 additions & 36 deletions src/main/java/com/corundumstudio/socketio/annotation/OnConnect.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
* Annotation that defines <b>Connect</b> handler.
*
* Arguments in method:
*
* - SocketIOClient (required)
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OnConnect {

}
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


/**
* Annotation that defines <b>Connect</b> handler.
*
* Arguments in method:
*
* - SocketIOClient (required)
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OnConnect {

}
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.handler.SocketIOException;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.namespace.Namespace;

public class OnConnectScanner implements AnnotationScanner {

@Override
public Class<? extends Annotation> getScanAnnotation() {
return OnConnect.class;
}

@Override
public void addListener(Namespace namespace, final Object object, final Method method, Annotation annotation) {
namespace.addConnectListener(new ConnectListener() {
@Override
public void onConnect(SocketIOClient client) {
try {
method.invoke(object, client);
} catch (InvocationTargetException e) {
throw new SocketIOException(e.getCause());
} catch (Exception e) {
throw new SocketIOException(e);
}
}
});
}

@Override
public void validate(Method method, Class<?> clazz) {
if (method.getParameterTypes().length != 1) {
throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
}
boolean valid = false;
for (Class<?> eventType : method.getParameterTypes()) {
if (eventType.equals(SocketIOClient.class)) {
valid = true;
}
}
if (!valid) {
throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
}
}

}
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.handler.SocketIOException;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.namespace.Namespace;

public class OnConnectScanner implements AnnotationScanner {

@Override
public Class<? extends Annotation> getScanAnnotation() {
return OnConnect.class;
}

@Override
public void addListener(Namespace namespace, final Object object, final Method method, Annotation annotation) {
namespace.addConnectListener(new ConnectListener() {
@Override
public void onConnect(SocketIOClient client) {
try {
method.invoke(object, client);
} catch (InvocationTargetException e) {
throw new SocketIOException(e.getCause());
} catch (Exception e) {
throw new SocketIOException(e);
}
}
});
}

@Override
public void validateListener(Method method, Class<?> clazz) {
if (method.getParameterTypes().length != 1) {
throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
}
boolean isValid = false;
for (Class<?> eventType : method.getParameterTypes()) {
if (eventType.equals(SocketIOClient.class)) {
isValid = true;
}
}
if (!isValid) {
throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation that defines <b>Disconnect</b> handler.
*
* Arguments in method:
*
* - SocketIOClient (required)
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OnDisconnect {

}
/**
* Copyright (c) 2012-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.corundumstudio.socketio.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation that defines <b>Disconnect</b> handler.
*
* Arguments in method:
*
* - SocketIOClient (required)
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OnDisconnect {

}

0 comments on commit 8b385cb

Please sign in to comment.