├── README.md ├── .gitignore └── tuna-java-sdk ├── ChangeLog.md ├── archive ├── aop-sdk-message-0.9.0.jar └── release.md ├── src ├── main │ └── java │ │ └── com │ │ └── alibaba │ │ └── tuna │ │ ├── fastjson │ │ ├── parser │ │ │ ├── AbstractJSONParser.java │ │ │ ├── deserializer │ │ │ │ ├── ParseProcess.java │ │ │ │ ├── ExtraProcessor.java │ │ │ │ ├── AutowiredObjectDeserializer.java │ │ │ │ ├── ExtraTypeProvider.java │ │ │ │ ├── ObjectDeserializer.java │ │ │ │ ├── JSONObjectDeserializer.java │ │ │ │ ├── JSONArrayDeserializer.java │ │ │ │ ├── MapResolveFieldDeserializer.java │ │ │ │ ├── CollectionResolveFieldDeserializer.java │ │ │ │ ├── DateFormatDeserializer.java │ │ │ │ ├── ClassDerializer.java │ │ │ │ └── CharArrayDeserializer.java │ │ │ ├── JavaBeanMapping.java │ │ │ ├── DefaultExtJSONParser.java │ │ │ └── ParseContext.java │ │ ├── serializer │ │ │ ├── SerializeFilter.java │ │ │ ├── JSONSerializerMap.java │ │ │ ├── ASMJavaBeanSerializer.java │ │ │ ├── ExceptionSerializer.java │ │ │ ├── PascalNameFilter.java │ │ │ ├── NameFilter.java │ │ │ ├── AppendableSerializer.java │ │ │ ├── ValueFilter.java │ │ │ ├── PropertyPreFilter.java │ │ │ ├── CharArraySerializer.java │ │ │ ├── SimpleDateFormatSerializer.java │ │ │ ├── AutowiredObjectSerializer.java │ │ │ ├── JSONSerializable.java │ │ │ ├── ObjectSerializer.java │ │ │ ├── PropertyFilter.java │ │ │ ├── BeforeFilter.java │ │ │ ├── AfterFilter.java │ │ │ ├── JSONLibDataFormatSerializer.java │ │ │ ├── JSONSerializableSerializer.java │ │ │ ├── ClassSerializer.java │ │ │ ├── ClobSeriliazer.java │ │ │ ├── JSONAwareSerializer.java │ │ │ ├── AtomicLongSerializer.java │ │ │ ├── TimeZoneCodec.java │ │ │ ├── AtomicIntegerSerializer.java │ │ │ ├── JSONStreamAwareSerializer.java │ │ │ ├── CharsetCodec.java │ │ │ ├── FileCodec.java │ │ │ ├── CurrencyCodec.java │ │ │ ├── AtomicBooleanSerializer.java │ │ │ ├── ByteArraySerializer.java │ │ │ ├── EnumSerializer.java │ │ │ ├── CalendarCodec.java │ │ │ ├── SerialContext.java │ │ │ └── LocaleCodec.java │ │ ├── asm │ │ │ └── ASMException.java │ │ ├── JSONPathException.java │ │ ├── annotation │ │ │ ├── JSONCreator.java │ │ │ ├── JSONType.java │ │ │ └── JSONField.java │ │ ├── TypeReference.java │ │ ├── util │ │ │ └── ParameterizedTypeImpl.java │ │ ├── JSONStreamContext.java │ │ ├── JSONAware.java │ │ ├── JSONStreamAware.java │ │ └── JSONException.java │ │ ├── client │ │ ├── api │ │ │ ├── TunaClient.java │ │ │ ├── ClientStartException.java │ │ │ ├── MessageProcessException.java │ │ │ └── AppInfo.java │ │ ├── httpcb │ │ │ ├── impl │ │ │ │ ├── netty │ │ │ │ │ └── HttpParamOutputStream.java │ │ │ │ ├── OpenSDKHttpServer.java │ │ │ │ ├── codec │ │ │ │ │ └── MessageDecoder.java │ │ │ │ └── Parts.java │ │ │ └── HttpCbMessage.java │ │ └── websocket │ │ │ ├── WebSocketMessageType.java │ │ │ └── WebSocketMessageHandler.java │ │ ├── util │ │ ├── CoderException.java │ │ ├── logging │ │ │ ├── package-info.java │ │ │ ├── Log4JLoggerFactory.java │ │ │ ├── JdkLoggerFactory.java │ │ │ ├── InternalLogLevel.java │ │ │ └── CommonsLoggerFactory.java │ │ └── GZIPHelper.java │ │ └── netty │ │ ├── util │ │ ├── package-info.java │ │ ├── concurrent │ │ │ ├── package-info.java │ │ │ ├── ScheduledFuture.java │ │ │ ├── FutureListener.java │ │ │ ├── GenericProgressiveFutureListener.java │ │ │ ├── ImmediateExecutor.java │ │ │ ├── GenericFutureListener.java │ │ │ ├── DefaultEventExecutor.java │ │ │ └── BlockingOperationException.java │ │ ├── internal │ │ │ ├── package-info.java │ │ │ ├── NoOpTypeParameterMatcher.java │ │ │ ├── FullyPaddedReference.java │ │ │ ├── LeftPadding.java │ │ │ ├── OneTimeTask.java │ │ │ ├── RightPaddedReference.java │ │ │ └── ReadOnlyIterator.java │ │ ├── AttributeMap.java │ │ ├── TimerTask.java │ │ └── ResourceLeak.java │ │ ├── handler │ │ ├── codec │ │ │ ├── http │ │ │ │ ├── multipart │ │ │ │ │ ├── package-info.java │ │ │ │ │ ├── Attribute.java │ │ │ │ │ ├── InterfaceHttpData.java │ │ │ │ │ └── CaseIgnoringComparator.java │ │ │ │ ├── package-info.java │ │ │ │ ├── cors │ │ │ │ │ └── package-info.java │ │ │ │ ├── FullHttpMessage.java │ │ │ │ ├── websocketx │ │ │ │ │ ├── WebSocketFrameDecoder.java │ │ │ │ │ ├── WebSocketFrameEncoder.java │ │ │ │ │ └── WebSocketHandshakeException.java │ │ │ │ ├── HttpObject.java │ │ │ │ ├── FullHttpResponse.java │ │ │ │ ├── FullHttpRequest.java │ │ │ │ ├── DefaultHttpObject.java │ │ │ │ ├── CookieHeaderNames.java │ │ │ │ ├── HttpMessage.java │ │ │ │ ├── HttpContent.java │ │ │ │ └── HttpResponseEncoder.java │ │ │ ├── rtsp │ │ │ │ ├── package-info.java │ │ │ │ └── RtspObjectEncoder.java │ │ │ ├── bytes │ │ │ │ └── package-info.java │ │ │ ├── string │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── serialization │ │ │ │ ├── package-info.java │ │ │ │ ├── ClassResolver.java │ │ │ │ ├── SoftReferenceMap.java │ │ │ │ ├── WeakReferenceMap.java │ │ │ │ ├── ClassLoaderClassResolver.java │ │ │ │ └── CachingClassResolver.java │ │ │ ├── base64 │ │ │ │ └── package-info.java │ │ │ ├── compression │ │ │ │ ├── package-info.java │ │ │ │ ├── ZlibDecoder.java │ │ │ │ └── ZlibWrapper.java │ │ │ ├── CodecException.java │ │ │ ├── DecoderException.java │ │ │ └── EncoderException.java │ │ ├── logging │ │ │ ├── package-info.java │ │ │ └── LogLevel.java │ │ ├── ssl │ │ │ ├── util │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── SslProvider.java │ │ │ └── NotSslRecordException.java │ │ ├── timeout │ │ │ ├── package-info.java │ │ │ ├── ReadTimeoutException.java │ │ │ ├── WriteTimeoutException.java │ │ │ ├── IdleState.java │ │ │ └── TimeoutException.java │ │ └── stream │ │ │ └── package-info.java │ │ ├── channel │ │ ├── socket │ │ │ ├── package-info.java │ │ │ ├── oio │ │ │ │ └── package-info.java │ │ │ ├── InternetProtocolFamily.java │ │ │ ├── nio │ │ │ │ ├── package-info.java │ │ │ │ └── ProtocolFamilyConverter.java │ │ │ ├── ServerSocketChannel.java │ │ │ └── ChannelInputShutdownEvent.java │ │ ├── local │ │ │ ├── package-info.java │ │ │ └── LocalEventLoop.java │ │ ├── oio │ │ │ └── package-info.java │ │ ├── embedded │ │ │ ├── package-info.java │ │ │ └── EmbeddedSocketAddress.java │ │ ├── group │ │ │ ├── package-info.java │ │ │ ├── ChannelMatcher.java │ │ │ └── ChannelGroupFutureListener.java │ │ ├── nio │ │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── ServerChannel.java │ │ ├── ChannelProgressiveFutureListener.java │ │ ├── EventLoop.java │ │ ├── ConnectTimeoutException.java │ │ ├── MessageSizeEstimator.java │ │ ├── EventLoopException.java │ │ ├── AddressedEnvelope.java │ │ ├── SucceededChannelFuture.java │ │ └── ChannelException.java │ │ ├── bootstrap │ │ ├── package-info.java │ │ └── ChannelFactory.java │ │ └── buffer │ │ └── ByteBufHolder.java └── assemble │ └── release.xml ├── README.md └── LICENSE.txt /README.md: -------------------------------------------------------------------------------- 1 | # [阿里巴巴开放平台](https://open.1688.com) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/target/* 2 | .project 3 | .settings 4 | .classpath 5 | *.iml 6 | .idea 7 | .svn 8 | -------------------------------------------------------------------------------- /tuna-java-sdk/ChangeLog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.9.0] - 2018-12-13 - archer.zb 4 | ### Added 5 | - 修复客户端返回401 bug 6 | - 新增客户端可自定义线程池大小feature -------------------------------------------------------------------------------- /tuna-java-sdk/archive/aop-sdk-message-0.9.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba/AliOpen/HEAD/tuna-java-sdk/archive/aop-sdk-message-0.9.0.jar -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/AbstractJSONParser.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser; 2 | 3 | public abstract class AbstractJSONParser { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/SerializeFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | 4 | public interface SerializeFilter { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/ParseProcess.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | 4 | public interface ParseProcess { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /tuna-java-sdk/archive/release.md: -------------------------------------------------------------------------------- 1 | # Releases 2 | 3 | ## 0.9.0 版本 - 2018-12-13 - archer.zb 4 | ### Assert 5 | [aop-sdk-message-0.9.0.jar][1] 6 | 7 | ### 变更 8 | - 修复客户端返回401 bug 9 | - 新增客户端可自定义线程池大小feature 10 | 11 | [1]: aop-sdk-message-0.9.0.jar -------------------------------------------------------------------------------- /tuna-java-sdk/README.md: -------------------------------------------------------------------------------- 1 | # 阿里巴巴开放平台消息 SDK 2 | 3 | 4 | ## 参考资料 5 | [消息接入说明](https://open.1688.com/doc/msgOverview.htm?id=546051) 6 | [消息推送说明](https://open.1688.com/doc/msgOverview.htm?id=546049) 7 | [SDK使用说明](https://open.1688.com/doc/msgOverview.htm?id=546052) -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/ExtraProcessor.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | /** 4 | * 5 | * 6 | * @since 1.1.34 7 | */ 8 | public interface ExtraProcessor extends ParseProcess { 9 | 10 | void processExtra(Object object, String key, Object value); 11 | } 12 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/AutowiredObjectDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Set; 5 | 6 | 7 | public interface AutowiredObjectDeserializer extends ObjectDeserializer{ 8 | Set getAutowiredFor(); 9 | } 10 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONSerializerMap.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | 4 | @Deprecated 5 | public class JSONSerializerMap extends SerializeConfig { 6 | public final boolean put(Class clazz, ObjectSerializer serializer) { 7 | return super.put(clazz, serializer); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/ExtraTypeProvider.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * 7 | * @since 1.1.34 8 | */ 9 | public interface ExtraTypeProvider extends ParseProcess { 10 | 11 | Type getExtraType(Object object, String key); 12 | } 13 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/JavaBeanMapping.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser; 2 | 3 | @Deprecated 4 | public class JavaBeanMapping extends ParserConfig { 5 | private final static JavaBeanMapping instance = new JavaBeanMapping(); 6 | 7 | public static JavaBeanMapping getGlobalInstance() { 8 | return instance; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/asm/ASMException.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.asm; 2 | 3 | import com.alibaba.tuna.fastjson.JSONException; 4 | 5 | public class ASMException extends JSONException { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | public ASMException(String message){ 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/api/TunaClient.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.client.api; 2 | 3 | /** 4 | * 客户端 5 | */ 6 | public interface TunaClient { 7 | 8 | /** 9 | * 启动客户端。一般在应用启动时调用 10 | * 11 | * @throws ClientStartException 12 | */ 13 | void start() throws ClientStartException; 14 | 15 | /** 16 | * 关闭客户端。一般在应用结束时调用 17 | */ 18 | void shutdown(); 19 | } 20 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/ObjectDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 6 | 7 | public interface ObjectDeserializer { 8 | T deserialze(DefaultJSONParser parser, Type type, Object fieldName); 9 | 10 | int getFastMatchToken(); 11 | } 12 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/JSONPathException.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson; 2 | 3 | public class JSONPathException extends JSONException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public JSONPathException(String message){ 8 | super(message); 9 | } 10 | 11 | public JSONPathException(String message, Throwable cause){ 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/annotation/JSONCreator.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ ElementType.CONSTRUCTOR, ElementType.METHOD }) 10 | public @interface JSONCreator { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ASMJavaBeanSerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | public abstract class ASMJavaBeanSerializer implements ObjectSerializer { 4 | 5 | protected JavaBeanSerializer nature; 6 | 7 | public ASMJavaBeanSerializer(Class clazz){ 8 | nature = new JavaBeanSerializer(clazz); 9 | } 10 | 11 | public JavaBeanSerializer getJavaBeanSerializer() { 12 | return nature; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ExceptionSerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | public class ExceptionSerializer extends JavaBeanSerializer { 6 | 7 | public ExceptionSerializer(Class clazz){ 8 | super(clazz); 9 | } 10 | 11 | protected boolean isWriteClassName(JSONSerializer serializer, Object obj, Type fieldType, Object fieldName) { 12 | return true; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/PascalNameFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | public class PascalNameFilter implements NameFilter { 4 | 5 | public String process(Object source, String name, Object value) { 6 | if (name == null || name.length() == 0) { 7 | return name; 8 | } 9 | 10 | char[] chars = name.toCharArray(); 11 | chars[0]= Character.toUpperCase(chars[0]); 12 | 13 | String pascalName = new String(chars); 14 | return pascalName; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/api/ClientStartException.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.client.api; 2 | 3 | /** 4 | * 客户端启动异常 5 | */ 6 | public class ClientStartException extends RuntimeException { 7 | private static final long serialVersionUID = -8767338692591458408L; 8 | 9 | public ClientStartException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | 13 | public ClientStartException(String message) { 14 | super(message); 15 | } 16 | 17 | public ClientStartException(Throwable cause) { 18 | super(cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/api/MessageProcessException.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.client.api; 2 | 3 | /** 4 | * 5 | */ 6 | public class MessageProcessException extends RuntimeException { 7 | private static final long serialVersionUID = 4661149938679072586L; 8 | 9 | public MessageProcessException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | 13 | public MessageProcessException(String message) { 14 | super(message); 15 | } 16 | 17 | public MessageProcessException(Throwable cause) { 18 | super(cause); 19 | } 20 | } -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/CoderException.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.util; 2 | 3 | public class CoderException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -5057120918998520756L; 9 | 10 | public CoderException() { 11 | super(); 12 | 13 | } 14 | 15 | public CoderException(String message, Throwable cause) { 16 | super(message, cause); 17 | 18 | } 19 | 20 | public CoderException(String message) { 21 | super(message); 22 | 23 | } 24 | 25 | public CoderException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/TypeReference.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.List; 6 | 7 | public class TypeReference { 8 | 9 | private final Type type; 10 | 11 | protected TypeReference(){ 12 | Type superClass = getClass().getGenericSuperclass(); 13 | 14 | type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; 15 | } 16 | 17 | public Type getType() { 18 | return type; 19 | } 20 | 21 | public final static Type LIST_STRING = new TypeReference>() {}.getType(); 22 | } 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/LICENSE.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/JSONObjectDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 6 | import com.alibaba.tuna.fastjson.parser.JSONToken; 7 | 8 | public class JSONObjectDeserializer implements ObjectDeserializer { 9 | public final static JSONObjectDeserializer instance = new JSONObjectDeserializer(); 10 | 11 | @SuppressWarnings("unchecked") 12 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 13 | return (T) parser.parseObject(); 14 | } 15 | 16 | public int getFastMatchToken() { 17 | return JSONToken.LBRACE; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/api/AppInfo.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.client.api; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 应用信息 7 | */ 8 | public class AppInfo implements Serializable { 9 | 10 | public AppInfo(String appKey, String secret) { 11 | this.appKey = appKey; 12 | this.secret = secret; 13 | } 14 | 15 | private String appKey; 16 | 17 | private String secret; 18 | 19 | public String getAppKey() { 20 | return appKey; 21 | } 22 | 23 | public void setAppKey(String appKey) { 24 | this.appKey = appKey; 25 | } 26 | 27 | public String getSecret() { 28 | return secret; 29 | } 30 | 31 | public void setSecret(String secret) { 32 | this.secret = secret; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Utility classes used across multiple packages. 19 | */ 20 | package com.alibaba.tuna.netty.util; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/JSONArrayDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.alibaba.tuna.fastjson.JSONArray; 6 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 7 | import com.alibaba.tuna.fastjson.parser.JSONToken; 8 | 9 | public class JSONArrayDeserializer implements ObjectDeserializer { 10 | public final static JSONArrayDeserializer instance = new JSONArrayDeserializer(); 11 | 12 | @SuppressWarnings("unchecked") 13 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 14 | JSONArray array = new JSONArray(); 15 | parser.parseArray(array); 16 | return (T) array; 17 | } 18 | 19 | public int getFastMatchToken() { 20 | return JSONToken.LBRACKET; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Utility classes for concurrent / async tasks. 19 | */ 20 | package com.alibaba.tuna.netty.util.concurrent; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/multipart/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * HTTP multipart support. 19 | */ 20 | package com.alibaba.tuna.netty.handler.codec.http.multipart; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder, decoder and their related message types for HTTP. 19 | */ 20 | package com.alibaba.tuna.netty.handler.codec.http; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/logging/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Logs a {@link io.netty.channel.ChannelEvent} for debugging purpose. 19 | */ 20 | package com.alibaba.tuna.netty.handler.logging; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/logging/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Internal-use-only logging API which is not allowed to be used outside Netty. 19 | */ 20 | package com.alibaba.tuna.util.logging; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/httpcb/impl/netty/HttpParamOutputStream.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.alibaba.tuna.client.httpcb.impl.netty; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.UnsupportedEncodingException; 8 | import java.util.Collections; 9 | import java.util.Map; 10 | 11 | import com.alibaba.tuna.client.httpcb.impl.HttpHelper; 12 | 13 | /** 14 | * 15 | * 16 | */ 17 | public class HttpParamOutputStream extends ByteArrayOutputStream { 18 | 19 | private String charset; 20 | 21 | public HttpParamOutputStream(String charset) { 22 | super(); 23 | this.charset = charset; 24 | } 25 | 26 | public Map toParameters() { 27 | try { 28 | String content = this.toString(charset); 29 | return HttpHelper.parseParameters(content); 30 | } catch (UnsupportedEncodingException e) { 31 | } 32 | return Collections.EMPTY_MAP; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/NameFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | public interface NameFilter extends SerializeFilter { 19 | String process(Object object, String name, Object value); 20 | } 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Abstract TCP and UDP socket interfaces which extend the core channel API. 19 | */ 20 | package com.alibaba.tuna.netty.channel.socket; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/ssl/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Utility classes that helps easier development of TLS/SSL applications. 19 | */ 20 | package com.alibaba.tuna.netty.handler.ssl.util; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AppendableSerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | 6 | public class AppendableSerializer implements ObjectSerializer { 7 | 8 | public final static AppendableSerializer instance = new AppendableSerializer(); 9 | 10 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 11 | if (object == null) { 12 | SerializeWriter out = serializer.getWriter(); 13 | if (out.isEnabled(SerializerFeature.WriteNullStringAsEmpty)) { 14 | out.writeString(""); 15 | } else { 16 | out.writeNull(); 17 | } 18 | return; 19 | } 20 | 21 | serializer.write(object.toString()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ValueFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | public interface ValueFilter extends SerializeFilter { 19 | 20 | Object process(Object object, String name, Object value); 21 | } 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/annotation/JSONType.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import com.alibaba.tuna.fastjson.parser.Feature; 9 | import com.alibaba.tuna.fastjson.serializer.SerializerFeature; 10 | 11 | /** 12 | * 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ ElementType.TYPE }) 16 | public @interface JSONType { 17 | 18 | boolean asm() default true; 19 | 20 | String[] orders() default {}; 21 | 22 | String[] ignores() default {}; 23 | 24 | SerializerFeature[] serialzeFeatures() default {}; 25 | Feature[] parseFeatures() default {}; 26 | 27 | boolean alphabetic() default true; 28 | 29 | Class mappingTo() default Void.class; 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/assemble/release.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | release 7 | 8 | zip 9 | 10 | false 11 | 12 | 13 | 14 | 15 | ${groupId}:${artifactId} 16 | 17 | 18 | 19 | lib 20 | 21 | ${groupId}:${artifactId} 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Internal-use-only utilities which is not allowed to be used 19 | * outside Netty. 20 | */ 21 | package com.alibaba.tuna.netty.util.internal; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/cors/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * This package contains Cross Origin Resource Sharing (CORS) related classes. 19 | */ 20 | package com.alibaba.tuna.netty.handler.codec.http.cors; 21 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/util/ParameterizedTypeImpl.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.util; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | 6 | public class ParameterizedTypeImpl implements ParameterizedType { 7 | 8 | private final Type[] actualTypeArguments; 9 | private final Type ownerType; 10 | private final Type rawType; 11 | 12 | public ParameterizedTypeImpl(Type[] actualTypeArguments, Type ownerType, Type rawType){ 13 | this.actualTypeArguments = actualTypeArguments; 14 | this.ownerType = ownerType; 15 | this.rawType = rawType; 16 | } 17 | 18 | public Type[] getActualTypeArguments() { 19 | return actualTypeArguments; 20 | } 21 | 22 | public Type getOwnerType() { 23 | return ownerType; 24 | } 25 | 26 | public Type getRawType() { 27 | return rawType; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/PropertyPreFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | public interface PropertyPreFilter extends SerializeFilter { 19 | 20 | boolean apply(JSONSerializer serializer, Object object, String name); 21 | } 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/local/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * A virtual transport that enables the communication between the two 19 | * parties in the same virtual machine. 20 | */ 21 | package com.alibaba.tuna.netty.channel.local; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/oio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Old blocking I/O based channel API implementation - recommended for 19 | * a small number of connections (< 1000). 20 | */ 21 | package com.alibaba.tuna.netty.channel.oio; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/CharArraySerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | 6 | 7 | public class CharArraySerializer implements ObjectSerializer { 8 | 9 | public static CharArraySerializer instance = new CharArraySerializer(); 10 | 11 | public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 12 | SerializeWriter out = serializer.getWriter(); 13 | 14 | if (object == null) { 15 | if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) { 16 | out.write("[]"); 17 | } else { 18 | out.writeNull(); 19 | } 20 | return; 21 | } 22 | 23 | char[] chars = (char[]) object; 24 | out.writeString(new String(chars)); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/JSONStreamContext.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson; 2 | 3 | class JSONStreamContext { 4 | 5 | final static int StartObject = 1001; 6 | final static int PropertyKey = 1002; 7 | final static int PropertyValue = 1003; 8 | final static int StartArray = 1004; 9 | final static int ArrayValue = 1005; 10 | 11 | private final JSONStreamContext parent; 12 | 13 | private int state; 14 | 15 | public JSONStreamContext(JSONStreamContext parent, int state){ 16 | this.parent = parent; 17 | this.state = state; 18 | } 19 | 20 | public JSONStreamContext getParent() { 21 | return parent; 22 | } 23 | 24 | public int getState() { 25 | return state; 26 | } 27 | 28 | public void setState(int state) { 29 | this.state = state; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/bootstrap/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * The helper classes with fluent API which enable an easy implementation of 19 | * typical client side and server side channel initialization. 20 | */ 21 | package com.alibaba.tuna.netty.bootstrap; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/oio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Old blocking I/O based socket channel API implementation - recommended for 19 | * a small number of connections (< 1000). 20 | */ 21 | package com.alibaba.tuna.netty.channel.socket.oio; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/rtsp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * An RTSP 19 | * extension based on the HTTP codec. 20 | */ 21 | package com.alibaba.tuna.netty.handler.codec.rtsp; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/timeout/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Adds support for read and write timeout and idle connection notification 19 | * using a {@link com.alibaba.tuna.netty.util.Timer}. 20 | */ 21 | package com.alibaba.tuna.netty.handler.timeout; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/SimpleDateFormatSerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | 8 | public class SimpleDateFormatSerializer implements ObjectSerializer { 9 | 10 | private final String pattern; 11 | 12 | public SimpleDateFormatSerializer(String pattern){ 13 | this.pattern = pattern; 14 | } 15 | 16 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 17 | if (object == null) { 18 | serializer.getWriter().writeNull(); 19 | return; 20 | } 21 | 22 | Date date = (Date) object; 23 | SimpleDateFormat format = new SimpleDateFormat(pattern); 24 | 25 | String text = format.format(date); 26 | serializer.write(text); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/MapResolveFieldDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Map; 5 | 6 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 7 | 8 | @SuppressWarnings("rawtypes") 9 | public final class MapResolveFieldDeserializer extends FieldDeserializer { 10 | 11 | private final String key; 12 | private final Map map; 13 | 14 | public MapResolveFieldDeserializer(Map map, String index){ 15 | super(null, null); 16 | this.key = index; 17 | this.map = map; 18 | } 19 | 20 | @SuppressWarnings("unchecked") 21 | public void setValue(Object object, Object value) { 22 | map.put(key, value); 23 | } 24 | 25 | 26 | @Override 27 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) { 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/embedded/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * A virtual {@link Channel} that helps wrapping a series of handlers to 19 | * unit test the handlers or use them in non-I/O context. 20 | */ 21 | package com.alibaba.tuna.netty.channel.embedded; 22 | 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/bytes/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder and decoder which transform an array of bytes into a 19 | * {@link com.alibaba.tuna.netty.buffer.ByteBuf} and vice versa. 20 | */ 21 | package com.alibaba.tuna.netty.handler.codec.bytes; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/ssl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * SSL · 19 | * TLS implementation based on {@link javax.net.ssl.SSLEngine} 20 | */ 21 | package com.alibaba.tuna.netty.handler.ssl; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/group/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * A channel registry which helps a user maintain the list of open 19 | * {@link com.alibaba.tuna.netty.channel.Channel}s and perform bulk operations on them. 20 | */ 21 | package com.alibaba.tuna.netty.channel.group; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/nio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * NIO-based channel 19 | * API implementation - recommended for a large number of connections (>= 1000). 20 | */ 21 | package com.alibaba.tuna.netty.channel.nio; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/string/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder and decoder which transform a {@link java.lang.String} into a 19 | * {@link com.alibaba.tuna.netty.buffer.ByteBuf} and vice versa. 20 | */ 21 | package com.alibaba.tuna.netty.handler.codec.string; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/CollectionResolveFieldDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Collection; 5 | import java.util.Map; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | 9 | @SuppressWarnings("rawtypes") 10 | public final class CollectionResolveFieldDeserializer extends FieldDeserializer { 11 | 12 | private final Collection collection; 13 | 14 | public CollectionResolveFieldDeserializer(DefaultJSONParser parser, Collection collection){ 15 | super(null, null); 16 | this.collection = collection; 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public void setValue(Object object, Object value) { 21 | collection.add(value); 22 | } 23 | 24 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) { 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/InternetProtocolFamily.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.socket; 17 | 18 | /** 19 | * Internet Protocol (IP) families used byte the {@link DatagramChannel} 20 | */ 21 | public enum InternetProtocolFamily { 22 | IPv4, 23 | IPv6 24 | } 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/ScheduledFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.concurrent; 17 | 18 | /** 19 | * The result of an scheduled asynchronous operation. 20 | */ 21 | public interface ScheduledFuture extends Future, java.util.concurrent.ScheduledFuture { 22 | } 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AutowiredObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.lang.reflect.Type; 19 | import java.util.Set; 20 | 21 | /** 22 | * 23 | */ 24 | public interface AutowiredObjectSerializer extends ObjectSerializer { 25 | Set getAutowiredFor(); 26 | } 27 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/nio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * NIO-based socket channel 19 | * API implementation - recommended for a large number of connections (>= 1000). 20 | */ 21 | package com.alibaba.tuna.netty.channel.socket.nio; 22 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/JSONAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson; 17 | 18 | /** 19 | * Beans that support customized output of JSON text shall implement this interface. 20 | * 21 | * 22 | */ 23 | public interface JSONAware { 24 | 25 | /** 26 | * @return JSON text 27 | */ 28 | String toJSONString(); 29 | } 30 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * The core channel API which is asynchronous and event-driven abstraction of 19 | * various transports such as a 20 | * NIO Channel. 21 | */ 22 | package com.alibaba.tuna.netty.channel; 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Extensible decoder and its common implementations which deal with the 19 | * packet fragmentation and reassembly issue found in a stream-based transport 20 | * such as TCP/IP. 21 | */ 22 | package com.alibaba.tuna.netty.handler.codec; 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/NoOpTypeParameterMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.internal; 18 | 19 | public final class NoOpTypeParameterMatcher extends TypeParameterMatcher { 20 | @Override 21 | public boolean match(Object msg) { 22 | return true; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/websocket/WebSocketMessageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.websocket; 18 | 19 | /** 20 | * WebSocket协议,报文类型 21 | */ 22 | public enum WebSocketMessageType { 23 | CONNECT,CONNECT_ACK,HEARTBEAT,CONFIRM,SERVER_PUSH,CLIENT_PUSH,CLOSE,SYSTEM; 24 | } 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder, decoder and their compatibility stream implementations which 19 | * transform a {@link java.io.Serializable} object into a byte buffer and 20 | * vice versa. 21 | */ 22 | package com.alibaba.tuna.netty.handler.codec.serialization; 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONSerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public interface JSONSerializable { 25 | void write(JSONSerializer serializer, Object fieldName, Type fieldType, int features) throws IOException; 26 | } 27 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/ClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.serialization; 17 | 18 | /** 19 | * please use {@link ClassResolvers} as instance factory 20 | */ 21 | public interface ClassResolver { 22 | 23 | Class resolve(String className) throws ClassNotFoundException; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/stream/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Writes very large data stream asynchronously neither spending a lot of 19 | * memory nor getting {@link java.lang.OutOfMemoryError}. For a detailed 20 | * example, please refer to {@code io.netty.example.http.file}. 21 | */ 22 | package com.alibaba.tuna.netty.handler.stream; 23 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public interface ObjectSerializer { 25 | 26 | void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException; 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/ssl/SslProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.handler.ssl; 18 | 19 | /** 20 | * An enumeration of SSL/TLS protocol providers. 21 | */ 22 | public enum SslProvider { 23 | /** 24 | * JDK's default implementation. 25 | */ 26 | JDK, 27 | /** 28 | * OpenSSL-based implementation. 29 | */ 30 | OPENSSL 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/httpcb/HttpCbMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.httpcb; 18 | 19 | import com.alibaba.tuna.client.api.MessageContent; 20 | 21 | /** 22 | * Http Callback 通道模式下,接收到的消息内容 23 | */ 24 | public class HttpCbMessage extends MessageContent { 25 | private static final long serialVersionUID = 9178226988772639455L; 26 | } 27 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/embedded/EmbeddedSocketAddress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.embedded; 17 | 18 | import java.net.SocketAddress; 19 | 20 | final class EmbeddedSocketAddress extends SocketAddress { 21 | private static final long serialVersionUID = 1400788804624980619L; 22 | 23 | @Override 24 | public String toString() { 25 | return "embedded"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/JSONStreamAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Beans that support customized output of JSON text to a writer shall implement this interface. 22 | * 23 | * 24 | */ 25 | public interface JSONStreamAware { 26 | 27 | /** 28 | * write JSON string to out. 29 | */ 30 | void writeJSONString(Appendable out) throws IOException; 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/base64/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder and decoder which transform a 19 | * Base64-encoded 20 | * {@link java.lang.String} or {@link com.alibaba.tuna.netty.buffer.ByteBuf} 21 | * into a decoded {@link com.alibaba.tuna.netty.buffer.ByteBuf} and vice versa. 22 | */ 23 | package com.alibaba.tuna.netty.handler.codec.base64; 24 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/bootstrap/ChannelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.bootstrap; 17 | 18 | import com.alibaba.tuna.netty.channel.Channel; 19 | 20 | /** 21 | * Factory that creates a new {@link Channel} on {@link Bootstrap#bind()}, {@link Bootstrap#connect()}, and 22 | * {@link ServerBootstrap#bind()}. 23 | */ 24 | public interface ChannelFactory { 25 | /** 26 | * Creates a new channel. 27 | */ 28 | T newChannel(); 29 | } 30 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/ServerChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | import com.alibaba.tuna.netty.channel.socket.ServerSocketChannel; 19 | 20 | /** 21 | * A {@link Channel} that accepts an incoming connection attempt and creates 22 | * its child {@link Channel}s by accepting them. {@link ServerSocketChannel} is 23 | * a good example. 24 | */ 25 | public interface ServerChannel extends Channel { 26 | // This is a tag interface. 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/httpcb/impl/OpenSDKHttpServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.httpcb.impl; 18 | 19 | import com.alibaba.tuna.client.api.TunaClient; 20 | 21 | /** 22 | * 23 | * 24 | */ 25 | public interface OpenSDKHttpServer extends TunaClient { 26 | 27 | public int getPort(); 28 | 29 | public void setPort(int port); 30 | 31 | public boolean isUseSSL(); 32 | 33 | public void setUseSSL(boolean useSSL); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/JSONException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson; 17 | 18 | /** 19 | * 20 | */ 21 | public class JSONException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | public JSONException(){ 26 | super(); 27 | } 28 | 29 | public JSONException(String message){ 30 | super(message); 31 | } 32 | 33 | public JSONException(String message, Throwable cause){ 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/PropertyFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | /** 19 | * 20 | */ 21 | public interface PropertyFilter extends SerializeFilter { 22 | 23 | /** 24 | * @param object the owner of the property 25 | * @param name the name of the property 26 | * @param value the value of the property 27 | * @return true if the property will be filtered out, false otherwise 28 | */ 29 | boolean apply(Object object, String name, Object value); 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/FutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.concurrent; 18 | 19 | /** 20 | * A subtype of {@link GenericFutureListener} that hides type parameter for convenience. 21 | *
22 |  * Future f = new DefaultPromise(..);
23 |  * f.addListener(new FutureListener() {
24 |  *     public void operationComplete(Future f) { .. }
25 |  * });
26 |  * 
27 | */ 28 | public interface FutureListener extends GenericFutureListener> { } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/compression/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | /** 18 | * Encoder and decoder which compresses and decompresses {@link com.alibaba.tuna.netty.buffer.ByteBuf}s 19 | * in a compression format such as zlib, 20 | * gzip, and 21 | * Snappy. 22 | */ 23 | package com.alibaba.tuna.netty.handler.codec.compression; 24 | // TODO Implement bzip2 and lzma handlers 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/logging/Log4JLoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.util.logging; 17 | 18 | import org.apache.log4j.Logger; 19 | 20 | /** 21 | * Logger factory which creates an 22 | * Apache Log4J 23 | * logger. 24 | */ 25 | public class Log4JLoggerFactory extends InternalLoggerFactory { 26 | 27 | @Override 28 | public InternalLogger newInstance(String name) { 29 | return new Log4JLogger(Logger.getLogger(name)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/BeforeFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | public abstract class BeforeFilter implements SerializeFilter { 4 | 5 | private static final ThreadLocal serializerLocal = new ThreadLocal(); 6 | private static final ThreadLocal seperatorLocal = new ThreadLocal(); 7 | 8 | private final static Character COMMA = Character.valueOf(','); 9 | 10 | final char writeBefore(JSONSerializer serializer, Object object, char seperator) { 11 | serializerLocal.set(serializer); 12 | seperatorLocal.set(seperator); 13 | writeBefore(object); 14 | serializerLocal.set(null); 15 | return seperatorLocal.get(); 16 | } 17 | 18 | protected final void writeKeyValue(String key, Object value) { 19 | JSONSerializer serializer = serializerLocal.get(); 20 | char seperator = seperatorLocal.get(); 21 | serializer.writeKeyValue(seperator, key, value); 22 | if (seperator != ',') { 23 | seperatorLocal.set(COMMA); 24 | } 25 | } 26 | 27 | public abstract void writeBefore(Object object); 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/FullyPaddedReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.internal; 18 | 19 | public final class FullyPaddedReference extends LeftPaddedReference { 20 | private static final long serialVersionUID = -5986650399506826641L; 21 | // cache line padding (must be public) 22 | public transient long rp1, rp2, rp3, rp4, rp5, rp6, rp7; // 56 bytes (excluding LeftPaddedReference.referent) 23 | public transient long rpA, rpB, rpC, rpD, rpE, rpF, rpG, rpH; // 64 bytes 24 | } 25 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/LeftPadding.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.internal; 18 | 19 | import java.io.Serializable; 20 | 21 | abstract class LeftPadding implements Serializable { 22 | private static final long serialVersionUID = -9129166504419549394L; 23 | // cache line padding (must be public) 24 | public transient long lp1, lp2, lp3, lp4, lp5, lp6; // 48 bytes (excluding 16-byte object header) 25 | public transient long lpA, lpB, lpC, lpD, lpE, lpF, lpG, lpH; // 64 bytes 26 | } 27 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/FullHttpMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | /** 19 | * Combines {@link HttpMessage} and {@link LastHttpContent} into one 20 | * message. So it represent a complete http message. 21 | */ 22 | public interface FullHttpMessage extends HttpMessage, LastHttpContent { 23 | @Override 24 | FullHttpMessage copy(); 25 | 26 | @Override 27 | FullHttpMessage retain(int increment); 28 | 29 | @Override 30 | FullHttpMessage retain(); 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/logging/JdkLoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.util.logging; 17 | 18 | 19 | import java.util.logging.Logger; 20 | 21 | /** 22 | * Logger factory which creates a 23 | * java.util.logging 24 | * logger. 25 | */ 26 | public class JdkLoggerFactory extends InternalLoggerFactory { 27 | 28 | @Override 29 | public InternalLogger newInstance(String name) { 30 | return new JdkLogger(Logger.getLogger(name)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/AttributeMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util; 17 | 18 | /** 19 | * Holds {@link Attribute}s which can be accessed via {@link AttributeKey}. 20 | * 21 | * Implementations must be Thread-safe. 22 | */ 23 | public interface AttributeMap { 24 | /** 25 | * Get the {@link Attribute} for the given {@link AttributeKey}. This method will never return null, but may return 26 | * an {@link Attribute} which does not have a value set yet. 27 | */ 28 | Attribute attr(AttributeKey key); 29 | } 30 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/websocketx/WebSocketFrameDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.websocketx; 17 | 18 | import com.alibaba.tuna.netty.channel.ChannelInboundHandler; 19 | import com.alibaba.tuna.netty.channel.ChannelPipeline; 20 | 21 | /** 22 | * Marker interface which all WebSocketFrame decoders need to implement. 23 | * 24 | * This makes it easier to access the added encoder later in the {@link ChannelPipeline}. 25 | */ 26 | public interface WebSocketFrameDecoder extends ChannelInboundHandler { 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/websocketx/WebSocketFrameEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.websocketx; 17 | 18 | import com.alibaba.tuna.netty.channel.ChannelOutboundHandler; 19 | import com.alibaba.tuna.netty.channel.ChannelPipeline; 20 | 21 | /** 22 | * Marker interface which all WebSocketFrame encoders need to implement. 23 | * 24 | * This makes it easier to access the added encoder later in the {@link ChannelPipeline}. 25 | */ 26 | public interface WebSocketFrameEncoder extends ChannelOutboundHandler { 27 | } 28 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/ChannelProgressiveFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | import java.util.EventListener; 19 | 20 | import com.alibaba.tuna.netty.util.concurrent.GenericProgressiveFutureListener; 21 | 22 | /** 23 | * An {@link EventListener} listener which will be called once the sending task associated with future is 24 | * being transferred. 25 | */ 26 | public interface ChannelProgressiveFutureListener extends GenericProgressiveFutureListener { 27 | // Just a type alias 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/SoftReferenceMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.serialization; 17 | 18 | import java.lang.ref.Reference; 19 | import java.lang.ref.SoftReference; 20 | import java.util.Map; 21 | 22 | final class SoftReferenceMap extends ReferenceMap { 23 | 24 | public SoftReferenceMap(Map> delegate) { 25 | super(delegate); 26 | } 27 | 28 | @Override 29 | Reference fold(V value) { 30 | return new SoftReference(value); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/WeakReferenceMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.serialization; 17 | 18 | import java.lang.ref.Reference; 19 | import java.lang.ref.WeakReference; 20 | import java.util.Map; 21 | 22 | final class WeakReferenceMap extends ReferenceMap { 23 | 24 | public WeakReferenceMap(Map> delegate) { 25 | super(delegate); 26 | } 27 | 28 | @Override 29 | Reference fold(V value) { 30 | return new WeakReference(value); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AfterFilter.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | /** 4 | * @since 1.1.35 5 | */ 6 | public abstract class AfterFilter implements SerializeFilter { 7 | 8 | private static final ThreadLocal serializerLocal = new ThreadLocal(); 9 | private static final ThreadLocal seperatorLocal = new ThreadLocal(); 10 | 11 | private final static Character COMMA = Character.valueOf(','); 12 | 13 | final char writeAfter(JSONSerializer serializer, Object object, char seperator) { 14 | serializerLocal.set(serializer); 15 | seperatorLocal.set(seperator); 16 | writeAfter(object); 17 | serializerLocal.set(null); 18 | return seperatorLocal.get(); 19 | } 20 | 21 | protected final void writeKeyValue(String key, Object value) { 22 | JSONSerializer serializer = serializerLocal.get(); 23 | char seperator = seperatorLocal.get(); 24 | serializer.writeKeyValue(seperator, key, value); 25 | if (seperator != ',') { 26 | seperatorLocal.set(COMMA); 27 | } 28 | } 29 | 30 | public abstract void writeAfter(Object object); 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/EventLoop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | import com.alibaba.tuna.netty.util.concurrent.EventExecutor; 19 | 20 | /** 21 | * Will handle all the I/O-Operations for a {@link Channel} once it was registered. 22 | * 23 | * One {@link EventLoop} instance will usually handle more then one {@link Channel} but this may depend on 24 | * implementation details and internals. 25 | * 26 | */ 27 | public interface EventLoop extends EventExecutor, EventLoopGroup { 28 | @Override 29 | EventLoopGroup parent(); 30 | } 31 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/timeout/ReadTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.timeout; 17 | 18 | /** 19 | * A {@link TimeoutException} raised by {@link ReadTimeoutHandler} when no data 20 | * was read within a certain period of time. 21 | */ 22 | public final class ReadTimeoutException extends TimeoutException { 23 | 24 | private static final long serialVersionUID = 169287984113283421L; 25 | 26 | public static final ReadTimeoutException INSTANCE = new ReadTimeoutException(); 27 | 28 | private ReadTimeoutException() { } 29 | } 30 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/logging/InternalLogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.util.logging; 17 | 18 | /** 19 | * The log level that {@link InternalLogger} can log at. 20 | */ 21 | public enum InternalLogLevel { 22 | /** 23 | * 'TRACE' log level. 24 | */ 25 | TRACE, 26 | /** 27 | * 'DEBUG' log level. 28 | */ 29 | DEBUG, 30 | /** 31 | * 'INFO' log level. 32 | */ 33 | INFO, 34 | /** 35 | * 'WARN' log level. 36 | */ 37 | WARN, 38 | /** 39 | * 'ERROR' log level. 40 | */ 41 | ERROR 42 | } 43 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/websocketx/WebSocketHandshakeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.websocketx; 17 | 18 | /** 19 | * Exception during handshaking process 20 | */ 21 | public class WebSocketHandshakeException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | public WebSocketHandshakeException(String s) { 26 | super(s); 27 | } 28 | 29 | public WebSocketHandshakeException(String s, Throwable throwable) { 30 | super(s, throwable); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/ServerSocketChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.socket; 17 | 18 | import java.net.InetSocketAddress; 19 | 20 | import com.alibaba.tuna.netty.channel.ServerChannel; 21 | 22 | /** 23 | * A TCP/IP {@link ServerChannel} which accepts incoming TCP/IP connections. 24 | */ 25 | public interface ServerSocketChannel extends ServerChannel { 26 | @Override 27 | ServerSocketChannelConfig config(); 28 | @Override 29 | InetSocketAddress localAddress(); 30 | @Override 31 | InetSocketAddress remoteAddress(); 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/timeout/WriteTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.timeout; 17 | 18 | /** 19 | * A {@link TimeoutException} raised by {@link WriteTimeoutHandler} when no data 20 | * was written within a certain period of time. 21 | */ 22 | public final class WriteTimeoutException extends TimeoutException { 23 | 24 | private static final long serialVersionUID = -144786655770296065L; 25 | 26 | public static final WriteTimeoutException INSTANCE = new WriteTimeoutException(); 27 | 28 | private WriteTimeoutException() { } 29 | } 30 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/DateFormatDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | import java.text.SimpleDateFormat; 5 | 6 | import com.alibaba.tuna.fastjson.JSONException; 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | 10 | public class DateFormatDeserializer extends AbstractDateDeserializer implements ObjectDeserializer { 11 | 12 | public final static DateFormatDeserializer instance = new DateFormatDeserializer(); 13 | 14 | @SuppressWarnings("unchecked") 15 | protected T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) { 16 | 17 | if (val == null) { 18 | return null; 19 | } 20 | 21 | if (val instanceof String) { 22 | String strVal = (String) val; 23 | if (strVal.length() == 0) { 24 | return null; 25 | } 26 | 27 | return (T) new SimpleDateFormat(strVal); 28 | } 29 | 30 | throw new JSONException("parse error"); 31 | } 32 | 33 | public int getFastMatchToken() { 34 | return JSONToken.LITERAL_STRING; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/timeout/IdleState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.timeout; 17 | 18 | import com.alibaba.tuna.netty.channel.Channel; 19 | 20 | 21 | /** 22 | * An {@link Enum} that represents the idle state of a {@link Channel}. 23 | */ 24 | public enum IdleState { 25 | /** 26 | * No data was received for a while. 27 | */ 28 | READER_IDLE, 29 | /** 30 | * No data was sent for a while. 31 | */ 32 | WRITER_IDLE, 33 | /** 34 | * No data was either received or sent for a while. 35 | */ 36 | ALL_IDLE 37 | } 38 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/TimerTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util; 17 | 18 | import java.util.concurrent.TimeUnit; 19 | 20 | /** 21 | * A task which is executed after the delay specified with 22 | * {@link Timer#newTimeout(TimerTask, long, TimeUnit)}. 23 | */ 24 | public interface TimerTask { 25 | 26 | /** 27 | * Executed after the delay specified with 28 | * {@link Timer#newTimeout(TimerTask, long, TimeUnit)}. 29 | * 30 | * @param timeout a handle which is associated with this task 31 | */ 32 | void run(Timeout timeout) throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/compression/ZlibDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.compression; 17 | 18 | import com.alibaba.tuna.netty.buffer.ByteBuf; 19 | import com.alibaba.tuna.netty.handler.codec.ByteToMessageDecoder; 20 | 21 | /** 22 | * Decompresses a {@link ByteBuf} using the deflate algorithm. 23 | */ 24 | public abstract class ZlibDecoder extends ByteToMessageDecoder { 25 | 26 | /** 27 | * Returns {@code true} if and only if the end of the compressed stream 28 | * has been reached. 29 | */ 30 | public abstract boolean isClosed(); 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/ResourceLeak.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util; 18 | 19 | public interface ResourceLeak { 20 | /** 21 | * Records the caller's current stack trace so that the {@link ResourceLeakDetector} can tell where the leaked 22 | * resource was accessed lastly. 23 | */ 24 | void record(); 25 | 26 | /** 27 | * Close the leak so that {@link ResourceLeakDetector} does not warn about leaked resources. 28 | * 29 | * @return {@code true} if called first time, {@code false} if called already 30 | */ 31 | boolean close(); 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/ConnectTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | import java.net.ConnectException; 19 | 20 | /** 21 | * {@link ConnectException} which will be thrown if a connection could 22 | * not be established because of a connection timeout. 23 | */ 24 | public class ConnectTimeoutException extends ConnectException { 25 | private static final long serialVersionUID = 2317065249988317463L; 26 | 27 | public ConnectTimeoutException(String msg) { 28 | super(msg); 29 | } 30 | 31 | public ConnectTimeoutException() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/group/ChannelMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.group; 17 | 18 | 19 | import com.alibaba.tuna.netty.channel.Channel; 20 | 21 | /** 22 | * Allows to only match some {@link Channel}'s for operations in {@link ChannelGroup}. 23 | * 24 | * {@link ChannelMatchers} provide you with helper methods for usual needed implementations. 25 | */ 26 | public interface ChannelMatcher { 27 | 28 | /** 29 | * Returns {@code true} if the operation should be also executed on the given {@link Channel}. 30 | */ 31 | boolean matches(Channel channel); 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/timeout/TimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.timeout; 17 | 18 | import com.alibaba.tuna.netty.channel.ChannelException; 19 | 20 | /** 21 | * A {@link TimeoutException} when no data was either read or written within a 22 | * certain period of time. 23 | */ 24 | public class TimeoutException extends ChannelException { 25 | 26 | private static final long serialVersionUID = 4673641882869672533L; 27 | 28 | TimeoutException() { } 29 | 30 | @Override 31 | public Throwable fillInStackTrace() { 32 | return this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONLibDataFormatSerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.util.Date; 6 | 7 | import com.alibaba.tuna.fastjson.JSONObject; 8 | 9 | public class JSONLibDataFormatSerializer implements ObjectSerializer { 10 | 11 | public JSONLibDataFormatSerializer(){ 12 | } 13 | 14 | @SuppressWarnings("deprecation") 15 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 16 | if (object == null) { 17 | serializer.getWriter().writeNull(); 18 | return; 19 | } 20 | 21 | Date date = (Date) object; 22 | 23 | JSONObject json = new JSONObject(); 24 | json.put("date", date.getDate()); 25 | json.put("day", date.getDay()); 26 | json.put("hours", date.getHours()); 27 | json.put("minutes", date.getMinutes()); 28 | json.put("month", date.getMonth()); 29 | json.put("seconds", date.getSeconds()); 30 | json.put("time", date.getTime()); 31 | json.put("timezoneOffset", date.getTimezoneOffset()); 32 | json.put("year", date.getYear()); 33 | 34 | serializer.write(json); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/group/ChannelGroupFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.group; 17 | 18 | import com.alibaba.tuna.netty.util.concurrent.GenericFutureListener; 19 | 20 | /** 21 | * Listens to the result of a {@link ChannelGroupFuture}. The result of the 22 | * asynchronous {@link ChannelGroup} I/O operations is notified once this 23 | * listener is added by calling {@link ChannelGroupFuture#addListener(GenericFutureListener)} 24 | * and all I/O operations are complete. 25 | */ 26 | public interface ChannelGroupFutureListener extends GenericFutureListener { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/HttpObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | import com.alibaba.tuna.netty.handler.codec.DecoderResult; 19 | 20 | public interface HttpObject { 21 | /** 22 | * Returns the result of decoding this message. 23 | */ 24 | DecoderResult getDecoderResult(); 25 | 26 | /** 27 | * Updates the result of decoding this message. This method is supposed to be invoked by {@link HttpObjectDecoder}. 28 | * Do not call this method unless you know what you are doing. 29 | */ 30 | void setDecoderResult(DecoderResult result); 31 | } 32 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/websocket/WebSocketMessageHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.websocket; 18 | 19 | import com.alibaba.tuna.client.api.MessageProcessException; 20 | 21 | /** 22 | * WebSocket 通道模式下,消息处理 Handler。需要用户实现。 23 | */ 24 | public interface WebSocketMessageHandler { 25 | 26 | /** 27 | * 消息通道客户端收到消息后,会回调该方法处理具体的业务,处理结果可以通过以下两种方式来表述: 28 | 29 | * @return false:消息处理失败,如未达重试次数上限,开放平台;true:消息处理成功。不会再重发。 30 | * @throws MessageProcessException 消息处理失败,消息通道将会择机重发消息 31 | */ 32 | public boolean onMessage(WebSocketMessage message) throws MessageProcessException; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONSerializableSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public class JSONSerializableSerializer implements ObjectSerializer { 25 | 26 | public static JSONSerializableSerializer instance = new JSONSerializableSerializer(); 27 | 28 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 29 | JSONSerializable jsonSerializable = ((JSONSerializable) object); 30 | jsonSerializable.write(serializer, fieldName, fieldType, 0); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/logging/LogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.logging; 17 | 18 | import com.alibaba.tuna.util.logging.InternalLogLevel; 19 | 20 | public enum LogLevel { 21 | TRACE(InternalLogLevel.TRACE), 22 | DEBUG(InternalLogLevel.DEBUG), 23 | INFO(InternalLogLevel.INFO), 24 | WARN(InternalLogLevel.WARN), 25 | ERROR(InternalLogLevel.ERROR); 26 | 27 | private final InternalLogLevel internalLevel; 28 | 29 | LogLevel(InternalLogLevel internalLevel) { 30 | this.internalLevel = internalLevel; 31 | } 32 | 33 | InternalLogLevel toInternalLevel() { 34 | return internalLevel; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ClassSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public class ClassSerializer implements ObjectSerializer { 25 | 26 | public final static ClassSerializer instance = new ClassSerializer(); 27 | 28 | @SuppressWarnings("rawtypes") 29 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 30 | SerializeWriter out = serializer.getWriter(); 31 | 32 | Class clazz = (Class) object; 33 | out.writeString(clazz.getName()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/OneTimeTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.internal; 17 | 18 | import com.alibaba.tuna.netty.util.concurrent.EventExecutor; 19 | 20 | /** 21 | * {@link Runnable} which represent a one time task which may allow the {@link EventExecutor} to reduce the amount of 22 | * produced garbage when queue it for execution. 23 | * 24 | * It is important this will not be reused. After submitted it is not allowed to get submitted again! 25 | */ 26 | public abstract class OneTimeTask extends MpscLinkedQueueNode implements Runnable { 27 | 28 | @Override 29 | public Runnable value() { 30 | return this; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ClobSeriliazer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.io.Reader; 5 | import java.io.StringWriter; 6 | import java.lang.reflect.Type; 7 | import java.sql.Clob; 8 | import java.sql.SQLException; 9 | 10 | public class ClobSeriliazer implements ObjectSerializer { 11 | 12 | public final static ClobSeriliazer instance = new ClobSeriliazer(); 13 | 14 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 15 | try { 16 | if (object == null) { 17 | serializer.writeNull(); 18 | return; 19 | } 20 | 21 | Clob clob = (Clob) object; 22 | Reader reader = clob.getCharacterStream(); 23 | 24 | StringWriter writer = new StringWriter(); 25 | char[] buf = new char[1024]; 26 | int len = 0; 27 | while ((len = reader.read(buf)) != -1) { 28 | writer.write(buf, 0, len); 29 | } 30 | reader.close(); 31 | 32 | String text = writer.toString(); 33 | serializer.write(text); 34 | } catch (SQLException e) { 35 | throw new IOException("write clob error", e); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/GenericProgressiveFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.concurrent; 18 | 19 | public interface GenericProgressiveFutureListener> extends GenericFutureListener { 20 | /** 21 | * Invoked when the operation has progressed. 22 | * 23 | * @param progress the progress of the operation so far (cumulative) 24 | * @param total the number that signifies the end of the operation when {@code progress} reaches at it. 25 | * {@code -1} if the end of operation is unknown. 26 | */ 27 | void operationProgressed(F future, long progress, long total) throws Exception; 28 | } 29 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONAwareSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | import com.alibaba.tuna.fastjson.JSONAware; 22 | 23 | /** 24 | * 25 | */ 26 | public class JSONAwareSerializer implements ObjectSerializer { 27 | 28 | public static JSONAwareSerializer instance = new JSONAwareSerializer(); 29 | 30 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 31 | SerializeWriter out = serializer.getWriter(); 32 | 33 | JSONAware aware = (JSONAware) object; 34 | out.write(aware.toJSONString()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/logging/CommonsLoggerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.util.logging; 17 | 18 | 19 | import org.apache.commons.logging.LogFactory; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * Logger factory which creates an 26 | * Apache Commons Logging 27 | * logger. 28 | */ 29 | public class CommonsLoggerFactory extends InternalLoggerFactory { 30 | 31 | Map loggerMap = new HashMap(); 32 | 33 | @Override 34 | public InternalLogger newInstance(String name) { 35 | return new CommonsLogger(LogFactory.getLog(name), name); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AtomicLongSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | import java.util.concurrent.atomic.AtomicLong; 21 | 22 | /** 23 | * 24 | */ 25 | public class AtomicLongSerializer implements ObjectSerializer { 26 | 27 | public final static AtomicLongSerializer instance = new AtomicLongSerializer(); 28 | 29 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 30 | SerializeWriter out = serializer.getWriter(); 31 | 32 | AtomicLong val = (AtomicLong) object; 33 | out.writeLong(val.get()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/ImmediateExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.concurrent; 17 | 18 | import java.util.concurrent.Executor; 19 | 20 | /** 21 | * {@link Executor} which execute tasks in the callers thread. 22 | */ 23 | public final class ImmediateExecutor implements Executor { 24 | public static final ImmediateExecutor INSTANCE = new ImmediateExecutor(); 25 | 26 | private ImmediateExecutor() { 27 | // use static instance 28 | } 29 | 30 | @Override 31 | public void execute(Runnable command) { 32 | if (command == null) { 33 | throw new NullPointerException("command"); 34 | } 35 | command.run(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/ClassDerializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.alibaba.tuna.fastjson.JSONException; 6 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 7 | import com.alibaba.tuna.fastjson.parser.JSONLexer; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.util.TypeUtils; 10 | 11 | public class ClassDerializer implements ObjectDeserializer { 12 | 13 | public final static ClassDerializer instance = new ClassDerializer(); 14 | 15 | public ClassDerializer(){ 16 | } 17 | 18 | @SuppressWarnings("unchecked") 19 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { 20 | JSONLexer lexer = parser.getLexer(); 21 | 22 | if (lexer.token() == JSONToken.NULL) { 23 | lexer.nextToken(); 24 | return null; 25 | } 26 | 27 | if (lexer.token() != JSONToken.LITERAL_STRING) { 28 | throw new JSONException("expect className"); 29 | } 30 | String className = lexer.stringVal(); 31 | lexer.nextToken(JSONToken.COMMA); 32 | 33 | return (T) TypeUtils.loadClass(className); 34 | } 35 | 36 | public int getFastMatchToken() { 37 | return JSONToken.LITERAL_STRING; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/FullHttpResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | /** 19 | * Combination of a {@link HttpResponse} and {@link FullHttpMessage}. 20 | * So it represent a complete http response. 21 | */ 22 | public interface FullHttpResponse extends HttpResponse, FullHttpMessage { 23 | @Override 24 | FullHttpResponse copy(); 25 | 26 | @Override 27 | FullHttpResponse retain(int increment); 28 | 29 | @Override 30 | FullHttpResponse retain(); 31 | 32 | @Override 33 | FullHttpResponse setProtocolVersion(HttpVersion version); 34 | 35 | @Override 36 | FullHttpResponse setStatus(HttpResponseStatus status); 37 | } 38 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/ClassLoaderClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.serialization; 17 | 18 | class ClassLoaderClassResolver implements ClassResolver { 19 | 20 | private final ClassLoader classLoader; 21 | 22 | ClassLoaderClassResolver(ClassLoader classLoader) { 23 | this.classLoader = classLoader; 24 | } 25 | 26 | @Override 27 | public Class resolve(String className) throws ClassNotFoundException { 28 | try { 29 | return classLoader.loadClass(className); 30 | } catch (ClassNotFoundException e) { 31 | return Class.forName(className, false, classLoader); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/TimeZoneCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.util.TimeZone; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 10 | 11 | public class TimeZoneCodec implements ObjectSerializer, ObjectDeserializer { 12 | 13 | public final static TimeZoneCodec instance = new TimeZoneCodec(); 14 | 15 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 16 | if (object == null) { 17 | serializer.writeNull(); 18 | return; 19 | } 20 | 21 | TimeZone timeZone = (TimeZone) object; 22 | serializer.write(timeZone.getID()); 23 | } 24 | 25 | @SuppressWarnings("unchecked") 26 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 27 | 28 | String id = (String) parser.parse(); 29 | 30 | if (id == null) { 31 | return null; 32 | } 33 | 34 | return (T) TimeZone.getTimeZone(id); 35 | } 36 | 37 | public int getFastMatchToken() { 38 | return JSONToken.LITERAL_STRING; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AtomicIntegerSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | /** 23 | * 24 | */ 25 | public class AtomicIntegerSerializer implements ObjectSerializer { 26 | 27 | public final static AtomicIntegerSerializer instance = new AtomicIntegerSerializer(); 28 | 29 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 30 | SerializeWriter out = serializer.getWriter(); 31 | 32 | AtomicInteger val = (AtomicInteger) object; 33 | out.writeInt(val.get()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/JSONStreamAwareSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | import com.alibaba.tuna.fastjson.JSONStreamAware; 22 | 23 | /** 24 | * 25 | */ 26 | public class JSONStreamAwareSerializer implements ObjectSerializer { 27 | 28 | public static JSONStreamAwareSerializer instance = new JSONStreamAwareSerializer(); 29 | 30 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 31 | SerializeWriter out = serializer.getWriter(); 32 | 33 | JSONStreamAware aware = (JSONStreamAware) object; 34 | aware.writeJSONString(out); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/GenericFutureListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.concurrent; 17 | 18 | import java.util.EventListener; 19 | 20 | /** 21 | * Listens to the result of a {@link Future}. The result of the asynchronous operation is notified once this listener 22 | * is added by calling {@link Future#addListener(GenericFutureListener)}. 23 | */ 24 | public interface GenericFutureListener> extends EventListener { 25 | 26 | /** 27 | * Invoked when the operation associated with the {@link Future} has been completed. 28 | * 29 | * @param future the source {@link Future} which called this callback 30 | */ 31 | void operationComplete(F future) throws Exception; 32 | } 33 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/RightPaddedReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.internal; 18 | 19 | import java.util.concurrent.atomic.AtomicReference; 20 | 21 | public final class RightPaddedReference extends AtomicReference { 22 | private static final long serialVersionUID = -467619563034125237L; 23 | 24 | // cache line padding (must be public) 25 | public transient long rp1, rp2, rp3, rp4, rp5; // 40 bytes (excluding AtomicReference.value and object header) 26 | public transient long rpA, rpB, rpC, rpD, rpE, rpF, rpG, rpH; // 64 bytes 27 | 28 | public RightPaddedReference() { } 29 | 30 | public RightPaddedReference(T initialValue) { 31 | super(initialValue); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/multipart/Attribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.multipart; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Attribute interface 22 | */ 23 | public interface Attribute extends HttpData { 24 | /** 25 | * Returns the value of this HttpData. 26 | */ 27 | String getValue() throws IOException; 28 | 29 | /** 30 | * Sets the value of this HttpData. 31 | */ 32 | void setValue(String value) throws IOException; 33 | 34 | @Override 35 | Attribute copy(); 36 | 37 | @Override 38 | Attribute duplicate(); 39 | 40 | @Override 41 | Attribute retain(); 42 | 43 | @Override 44 | Attribute retain(int increment); 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/multipart/InterfaceHttpData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.multipart; 17 | 18 | import com.alibaba.tuna.netty.util.ReferenceCounted; 19 | 20 | /** 21 | * Interface for all Objects that could be encoded/decoded using HttpPostRequestEncoder/Decoder 22 | */ 23 | public interface InterfaceHttpData extends Comparable, ReferenceCounted { 24 | enum HttpDataType { 25 | Attribute, FileUpload, InternalAttribute 26 | } 27 | 28 | /** 29 | * Returns the name of this InterfaceHttpData. 30 | */ 31 | String getName(); 32 | 33 | /** 34 | * 35 | * @return The HttpDataType 36 | */ 37 | HttpDataType getHttpDataType(); 38 | } 39 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/CharsetCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.nio.charset.Charset; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 10 | 11 | 12 | public class CharsetCodec implements ObjectSerializer, ObjectDeserializer { 13 | 14 | public final static CharsetCodec instance = new CharsetCodec(); 15 | 16 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 17 | if (object == null) { 18 | serializer.writeNull(); 19 | return; 20 | } 21 | 22 | Charset charset = (Charset) object; 23 | serializer.write(charset.toString()); 24 | } 25 | 26 | @SuppressWarnings("unchecked") 27 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 28 | Object value = parser.parse(); 29 | 30 | if (value == null) { 31 | return null; 32 | } 33 | 34 | String charset = (String) value; 35 | 36 | return (T) Charset.forName(charset); 37 | } 38 | 39 | public int getFastMatchToken() { 40 | return JSONToken.LITERAL_STRING; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/FullHttpRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | /** 19 | * Combinate the {@link HttpRequest} and {@link FullHttpMessage}, so the request is a complete HTTP 20 | * request. 21 | */ 22 | public interface FullHttpRequest extends HttpRequest, FullHttpMessage { 23 | @Override 24 | FullHttpRequest copy(); 25 | 26 | @Override 27 | FullHttpRequest retain(int increment); 28 | 29 | @Override 30 | FullHttpRequest retain(); 31 | 32 | @Override 33 | FullHttpRequest setProtocolVersion(HttpVersion version); 34 | 35 | @Override 36 | FullHttpRequest setMethod(HttpMethod method); 37 | 38 | @Override 39 | FullHttpRequest setUri(String uri); 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/DefaultExtJSONParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.parser; 17 | 18 | 19 | /** 20 | * 21 | */ 22 | @Deprecated 23 | public class DefaultExtJSONParser extends DefaultJSONParser { 24 | 25 | public DefaultExtJSONParser(String input){ 26 | this(input, ParserConfig.getGlobalInstance()); 27 | } 28 | 29 | public DefaultExtJSONParser(String input, ParserConfig mapping){ 30 | super(input, mapping); 31 | } 32 | 33 | public DefaultExtJSONParser(String input, ParserConfig mapping, int features){ 34 | super(input, mapping, features); 35 | } 36 | 37 | public DefaultExtJSONParser(char[] input, int length, ParserConfig mapping, int features){ 38 | super(input, length, mapping, features); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/FileCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.reflect.Type; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 10 | 11 | public class FileCodec implements ObjectSerializer, ObjectDeserializer { 12 | 13 | public static FileCodec instance = new FileCodec(); 14 | 15 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 16 | SerializeWriter out = serializer.getWriter(); 17 | 18 | if (object == null) { 19 | out.writeNull(); 20 | return; 21 | } 22 | 23 | File file = (File) object; 24 | 25 | serializer.write(file.getPath()); 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 30 | Object value = parser.parse(); 31 | 32 | if (value == null) { 33 | return null; 34 | } 35 | 36 | String path = (String) value; 37 | 38 | return (T) new File(path); 39 | } 40 | 41 | public int getFastMatchToken() { 42 | return JSONToken.LITERAL_STRING; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/CurrencyCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.util.Currency; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 10 | 11 | public class CurrencyCodec implements ObjectSerializer, ObjectDeserializer { 12 | 13 | public final static CurrencyCodec instance = new CurrencyCodec(); 14 | 15 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 16 | final SerializeWriter out = serializer.getWriter(); 17 | if (object == null) { 18 | out.writeNull(); 19 | } else { 20 | Currency currency = (Currency) object; 21 | out.writeString(currency.getCurrencyCode()); 22 | } 23 | } 24 | 25 | @SuppressWarnings("unchecked") 26 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { 27 | String text = (String) parser.parse(); 28 | 29 | if (text == null || text.length() == 0) { 30 | return null; 31 | } 32 | 33 | return (T) Currency.getInstance(text); 34 | } 35 | 36 | public int getFastMatchToken() { 37 | return JSONToken.LITERAL_STRING; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/MessageSizeEstimator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | /** 19 | * Responsible to estimate size of a message. The size represent how much memory the message will ca. reserve in 20 | * memory. 21 | */ 22 | public interface MessageSizeEstimator { 23 | 24 | /** 25 | * Creates a new handle. The handle provides the actual operations. 26 | */ 27 | Handle newHandle(); 28 | 29 | interface Handle { 30 | 31 | /** 32 | * Calculate the size of the given message. 33 | * 34 | * @param msg The message for which the size should be calculated 35 | * @return size The size in bytes. The returned size must be >= 0 36 | */ 37 | int size(Object msg); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/ParseContext.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | public class ParseContext { 6 | 7 | private Object object; 8 | private final ParseContext parent; 9 | private final Object fieldName; 10 | private Type type; 11 | 12 | public ParseContext(ParseContext parent, Object object, Object fieldName){ 13 | super(); 14 | this.parent = parent; 15 | this.object = object; 16 | this.fieldName = fieldName; 17 | } 18 | 19 | public Type getType() { 20 | return type; 21 | } 22 | 23 | public void setType(Type type) { 24 | this.type = type; 25 | } 26 | 27 | public Object getObject() { 28 | return object; 29 | } 30 | 31 | public void setObject(Object object) { 32 | this.object = object; 33 | } 34 | 35 | public ParseContext getParentContext() { 36 | return parent; 37 | } 38 | 39 | public String getPath() { 40 | if (parent == null) { 41 | return "$"; 42 | } else { 43 | if (fieldName instanceof Integer) { 44 | return parent.getPath() + "[" + fieldName + "]"; 45 | } else { 46 | return parent.getPath() + "." + fieldName; 47 | } 48 | 49 | } 50 | } 51 | 52 | public String toString() { 53 | return this.getPath(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/EventLoopException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | /** 19 | * Special {@link ChannelException} which will be thrown by {@link EventLoop} and {@link EventLoopGroup} 20 | * implementations when an error occurs. 21 | */ 22 | public class EventLoopException extends ChannelException { 23 | 24 | private static final long serialVersionUID = -8969100344583703616L; 25 | 26 | public EventLoopException() { 27 | } 28 | 29 | public EventLoopException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public EventLoopException(String message) { 34 | super(message); 35 | } 36 | 37 | public EventLoopException(Throwable cause) { 38 | super(cause); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/util/GZIPHelper.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.util; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.util.zip.GZIPInputStream; 7 | import java.util.zip.GZIPOutputStream; 8 | 9 | public class GZIPHelper { 10 | public static byte[] zip(byte[] value) throws IOException { 11 | ByteArrayOutputStream output = null; 12 | GZIPOutputStream zip = null; 13 | try { 14 | output = new ByteArrayOutputStream(); 15 | zip = new GZIPOutputStream(output); 16 | zip.write(value, 0, value.length); 17 | zip.close(); 18 | return output.toByteArray(); 19 | } finally { 20 | if (zip != null) 21 | zip.close(); 22 | if (output != null) 23 | output.close(); 24 | } 25 | } 26 | 27 | public static byte[] unzip(byte[] value) throws IOException { 28 | ByteArrayOutputStream output = null; 29 | ByteArrayInputStream input = null; 30 | GZIPInputStream zip = null; 31 | try { 32 | output = new ByteArrayOutputStream(); 33 | input = new ByteArrayInputStream(value); 34 | zip = new GZIPInputStream(input); 35 | byte[] buffer = new byte[1024]; 36 | int read; 37 | while ((read = zip.read(buffer)) > 0) 38 | output.write(buffer, 0, read); 39 | return output.toByteArray(); 40 | } finally { 41 | if (zip != null) 42 | zip.close(); 43 | if (output != null) 44 | output.close(); 45 | if (input != null) 46 | input.close(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/multipart/CaseIgnoringComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http.multipart; 17 | 18 | import java.io.Serializable; 19 | import java.util.Comparator; 20 | 21 | final class CaseIgnoringComparator implements Comparator, Serializable { 22 | 23 | private static final long serialVersionUID = 4582133183775373862L; 24 | 25 | static final CaseIgnoringComparator INSTANCE = new CaseIgnoringComparator(); 26 | 27 | private CaseIgnoringComparator() { 28 | } 29 | 30 | @Override 31 | public int compare(String o1, String o2) { 32 | return o1.compareToIgnoreCase(o2); 33 | } 34 | 35 | @SuppressWarnings("MethodMayBeStatic") 36 | private Object readResolve() { 37 | return INSTANCE; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/local/LocalEventLoop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.local; 17 | 18 | import java.util.concurrent.ThreadFactory; 19 | 20 | import com.alibaba.tuna.netty.channel.SingleThreadEventLoop; 21 | 22 | final class LocalEventLoop extends SingleThreadEventLoop { 23 | 24 | LocalEventLoop(LocalEventLoopGroup parent, ThreadFactory threadFactory) { 25 | super(parent, threadFactory, true); 26 | } 27 | 28 | @Override 29 | protected void run() { 30 | for (;;) { 31 | Runnable task = takeTask(); 32 | if (task != null) { 33 | task.run(); 34 | updateLastExecutionTime(); 35 | } 36 | 37 | if (confirmShutdown()) { 38 | break; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/DefaultHttpObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | import com.alibaba.tuna.netty.handler.codec.DecoderResult; 19 | 20 | public class DefaultHttpObject implements HttpObject { 21 | 22 | private DecoderResult decoderResult = DecoderResult.SUCCESS; 23 | 24 | protected DefaultHttpObject() { 25 | // Disallow direct instantiation 26 | } 27 | 28 | @Override 29 | public DecoderResult getDecoderResult() { 30 | return decoderResult; 31 | } 32 | 33 | @Override 34 | public void setDecoderResult(DecoderResult decoderResult) { 35 | if (decoderResult == null) { 36 | throw new NullPointerException("decoderResult"); 37 | } 38 | this.decoderResult = decoderResult; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/httpcb/impl/codec/MessageDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.httpcb.impl.codec; 18 | 19 | import java.util.Map; 20 | 21 | import com.alibaba.tuna.fastjson.JSON; 22 | import com.alibaba.tuna.client.httpcb.impl.AlibabaHttpRequest; 23 | 24 | /** 25 | * 26 | * 27 | */ 28 | public class MessageDecoder { 29 | 30 | public void decodeTo(Map requestParameter, Class resultType, 31 | AlibabaHttpRequest alibabaHttpRequest) { 32 | String signature = requestParameter.get("_aop_signature"); 33 | alibabaHttpRequest.setSignatureFromClient(signature); 34 | String message = requestParameter.get("message"); 35 | T result = JSON.parseObject(message, resultType); 36 | alibabaHttpRequest.setRequestContent(result); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/AtomicBooleanSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | import java.util.concurrent.atomic.AtomicBoolean; 21 | 22 | /** 23 | * 24 | */ 25 | public class AtomicBooleanSerializer implements ObjectSerializer { 26 | 27 | public final static AtomicBooleanSerializer instance = new AtomicBooleanSerializer(); 28 | 29 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 30 | SerializeWriter out = serializer.getWriter(); 31 | 32 | AtomicBoolean val = (AtomicBoolean) object; 33 | if (val.get()) { 34 | out.append("true"); 35 | } else { 36 | out.append("false"); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/CookieHeaderNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | final class CookieHeaderNames { 19 | static final String PATH = "Path"; 20 | 21 | static final String EXPIRES = "Expires"; 22 | 23 | static final String MAX_AGE = "Max-Age"; 24 | 25 | static final String DOMAIN = "Domain"; 26 | 27 | static final String SECURE = "Secure"; 28 | 29 | static final String HTTPONLY = "HTTPOnly"; 30 | 31 | static final String COMMENT = "Comment"; 32 | 33 | static final String COMMENTURL = "CommentURL"; 34 | 35 | static final String DISCARD = "Discard"; 36 | 37 | static final String PORT = "Port"; 38 | 39 | static final String VERSION = "Version"; 40 | 41 | private CookieHeaderNames() { 42 | // Unused. 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/buffer/ByteBufHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.buffer; 17 | 18 | import com.alibaba.tuna.netty.util.ReferenceCounted; 19 | 20 | /** 21 | * A packet which is send or receive. 22 | */ 23 | public interface ByteBufHolder extends ReferenceCounted { 24 | 25 | /** 26 | * Return the data which is held by this {@link ByteBufHolder}. 27 | */ 28 | ByteBuf content(); 29 | 30 | /** 31 | * Create a deep copy of this {@link ByteBufHolder}. 32 | */ 33 | ByteBufHolder copy(); 34 | 35 | /** 36 | * Duplicate the {@link ByteBufHolder}. Be aware that this will not automatically call {@link #retain()}. 37 | */ 38 | ByteBufHolder duplicate(); 39 | 40 | @Override 41 | ByteBufHolder retain(); 42 | 43 | @Override 44 | ByteBufHolder retain(int increment); 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/ChannelInputShutdownEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.socket; 17 | 18 | import com.alibaba.tuna.netty.channel.ChannelHandlerContext; 19 | import com.alibaba.tuna.netty.channel.ChannelInboundHandler; 20 | 21 | /** 22 | * Special event which will be fired and passed to the 23 | * {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} methods once the input of 24 | * a {@link SocketChannel} was shutdown and the {@link SocketChannelConfig#isAllowHalfClosure()} method returns 25 | * {@code true}. 26 | */ 27 | public final class ChannelInputShutdownEvent { 28 | 29 | /** 30 | * Instance to use 31 | */ 32 | public static final ChannelInputShutdownEvent INSTANCE = new ChannelInputShutdownEvent(); 33 | 34 | private ChannelInputShutdownEvent() { } 35 | } 36 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/internal/ReadOnlyIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.util.internal; 18 | 19 | import java.util.Iterator; 20 | 21 | public final class ReadOnlyIterator implements Iterator { 22 | private final Iterator iterator; 23 | 24 | public ReadOnlyIterator(Iterator iterator) { 25 | if (iterator == null) { 26 | throw new NullPointerException("iterator"); 27 | } 28 | this.iterator = iterator; 29 | } 30 | 31 | @Override 32 | public boolean hasNext() { 33 | return iterator.hasNext(); 34 | } 35 | 36 | @Override 37 | public T next() { 38 | return iterator.next(); 39 | } 40 | 41 | @Override 42 | public void remove() { 43 | throw new UnsupportedOperationException("read-only"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/AddressedEnvelope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | 17 | package com.alibaba.tuna.netty.channel; 18 | 19 | import java.net.SocketAddress; 20 | 21 | import com.alibaba.tuna.netty.util.ReferenceCounted; 22 | 23 | /** 24 | * A message that wraps another message with a sender address and a recipient address. 25 | * 26 | * @param the type of the wrapped message 27 | * @param the type of the address 28 | */ 29 | public interface AddressedEnvelope extends ReferenceCounted { 30 | /** 31 | * Returns the message wrapped by this envelope message. 32 | */ 33 | M content(); 34 | 35 | /** 36 | * Returns the address of the sender of this message. 37 | */ 38 | A sender(); 39 | 40 | /** 41 | * Returns the address of the recipient of this message. 42 | */ 43 | A recipient(); 44 | } 45 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/client/httpcb/impl/Parts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Netty Project 3 | * Copyright (C) 1999-2018 Alibaba Group Holding Limited 4 | * All rights reserved. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.alibaba.tuna.client.httpcb.impl; 18 | 19 | /** 20 | * 21 | * 22 | */ 23 | public class Parts { 24 | 25 | private String path; 26 | private String query; 27 | private String ref; 28 | 29 | public Parts(String file) { 30 | int ind = file.indexOf('#'); 31 | ref = ind < 0 ? null : file.substring(ind + 1); 32 | file = ind < 0 ? file : file.substring(0, ind); 33 | int q = file.lastIndexOf('?'); 34 | if (q != -1) { 35 | query = file.substring(q + 1); 36 | path = file.substring(0, q); 37 | } else { 38 | path = file; 39 | } 40 | } 41 | 42 | public String getPath() { 43 | return path; 44 | } 45 | 46 | public String getQuery() { 47 | return query; 48 | } 49 | 50 | public String getRef() { 51 | return ref; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/HttpMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | 19 | /** 20 | * An interface that defines a HTTP message, providing common properties for 21 | * {@link HttpRequest} and {@link HttpResponse}. 22 | * 23 | * @see HttpResponse 24 | * @see HttpRequest 25 | * @see HttpHeaders 26 | */ 27 | public interface HttpMessage extends HttpObject { 28 | 29 | /** 30 | * Returns the protocol version of this {@link HttpMessage} 31 | * 32 | * @return The protocol version 33 | */ 34 | HttpVersion getProtocolVersion(); 35 | 36 | /** 37 | * Set the protocol version of this {@link HttpMessage} 38 | */ 39 | HttpMessage setProtocolVersion(HttpVersion version); 40 | 41 | /** 42 | * Returns the headers of this message. 43 | */ 44 | HttpHeaders headers(); 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/compression/ZlibWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.compression; 17 | 18 | /** 19 | * The container file formats that wrap the stream compressed by the DEFLATE 20 | * algorithm. 21 | */ 22 | public enum ZlibWrapper { 23 | /** 24 | * The ZLIB wrapper as specified in RFC 1950. 25 | */ 26 | ZLIB, 27 | /** 28 | * The GZIP wrapper as specified in RFC 1952. 29 | */ 30 | GZIP, 31 | /** 32 | * Raw DEFLATE stream only (no header and no footer). 33 | */ 34 | NONE, 35 | /** 36 | * Try {@link #ZLIB} first and then {@link #NONE} if the first attempt fails. 37 | * Please note that you can specify this wrapper type only when decompressing. 38 | */ 39 | ZLIB_OR_NONE 40 | } 41 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/CodecException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec; 17 | 18 | /** 19 | * An {@link Exception} which is thrown by a codec. 20 | */ 21 | public class CodecException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = -1464830400709348473L; 24 | 25 | /** 26 | * Creates a new instance. 27 | */ 28 | public CodecException() { 29 | } 30 | 31 | /** 32 | * Creates a new instance. 33 | */ 34 | public CodecException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | /** 39 | * Creates a new instance. 40 | */ 41 | public CodecException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Creates a new instance. 47 | */ 48 | public CodecException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/ByteArraySerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public class ByteArraySerializer implements ObjectSerializer { 25 | 26 | public static ByteArraySerializer instance = new ByteArraySerializer(); 27 | 28 | public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 29 | SerializeWriter out = serializer.getWriter(); 30 | 31 | if (object == null) { 32 | if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) { 33 | out.write("[]"); 34 | } else { 35 | out.writeNull(); 36 | } 37 | return; 38 | } 39 | 40 | byte[] array = (byte[]) object; 41 | out.writeByteArray(array); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/SucceededChannelFuture.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | import com.alibaba.tuna.netty.util.concurrent.EventExecutor; 19 | 20 | /** 21 | * The {@link CompleteChannelFuture} which is succeeded already. It is 22 | * recommended to use {@link Channel#newSucceededFuture()} instead of 23 | * calling the constructor of this future. 24 | */ 25 | final class SucceededChannelFuture extends CompleteChannelFuture { 26 | 27 | /** 28 | * Creates a new instance. 29 | * 30 | * @param channel the {@link Channel} associated with this future 31 | */ 32 | public SucceededChannelFuture(Channel channel, EventExecutor executor) { 33 | super(channel, executor); 34 | } 35 | 36 | @Override 37 | public Throwable cause() { 38 | return null; 39 | } 40 | 41 | @Override 42 | public boolean isSuccess() { 43 | return true; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/DecoderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec; 17 | 18 | /** 19 | * An {@link CodecException} which is thrown by a dencoder. 20 | */ 21 | public class DecoderException extends CodecException { 22 | 23 | private static final long serialVersionUID = 6926716840699621852L; 24 | 25 | /** 26 | * Creates a new instance. 27 | */ 28 | public DecoderException() { 29 | } 30 | 31 | /** 32 | * Creates a new instance. 33 | */ 34 | public DecoderException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | /** 39 | * Creates a new instance. 40 | */ 41 | public DecoderException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Creates a new instance. 47 | */ 48 | public DecoderException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/EncoderException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec; 17 | 18 | /** 19 | * An {@link CodecException} which is thrown by an encoder. 20 | */ 21 | public class EncoderException extends CodecException { 22 | 23 | private static final long serialVersionUID = -5086121160476476774L; 24 | 25 | /** 26 | * Creates a new instance. 27 | */ 28 | public EncoderException() { 29 | } 30 | 31 | /** 32 | * Creates a new instance. 33 | */ 34 | public EncoderException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | /** 39 | * Creates a new instance. 40 | */ 41 | public EncoderException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Creates a new instance. 47 | */ 48 | public EncoderException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/DefaultEventExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.concurrent; 17 | 18 | import java.util.concurrent.ThreadFactory; 19 | 20 | /** 21 | * Default {@link SingleThreadEventExecutor} implementation which just execute all submitted task in a 22 | * serial fashion 23 | * 24 | */ 25 | final class DefaultEventExecutor extends SingleThreadEventExecutor { 26 | 27 | DefaultEventExecutor(DefaultEventExecutorGroup parent, ThreadFactory threadFactory) { 28 | super(parent, threadFactory, true); 29 | } 30 | 31 | @Override 32 | protected void run() { 33 | for (;;) { 34 | Runnable task = takeTask(); 35 | if (task != null) { 36 | task.run(); 37 | updateLastExecutionTime(); 38 | } 39 | 40 | if (confirmShutdown()) { 41 | break; 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/ChannelException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel; 17 | 18 | /** 19 | * A {@link RuntimeException} which is thrown when an I/O operation fails. 20 | */ 21 | public class ChannelException extends RuntimeException { 22 | 23 | private static final long serialVersionUID = 2908618315971075004L; 24 | 25 | /** 26 | * Creates a new exception. 27 | */ 28 | public ChannelException() { 29 | } 30 | 31 | /** 32 | * Creates a new exception. 33 | */ 34 | public ChannelException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | 38 | /** 39 | * Creates a new exception. 40 | */ 41 | public ChannelException(String message) { 42 | super(message); 43 | } 44 | 45 | /** 46 | * Creates a new exception. 47 | */ 48 | public ChannelException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/rtsp/RtspObjectEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.rtsp; 17 | 18 | import com.alibaba.tuna.netty.buffer.ByteBuf; 19 | import com.alibaba.tuna.netty.channel.ChannelHandler.Sharable; 20 | import com.alibaba.tuna.netty.handler.codec.http.FullHttpMessage; 21 | import com.alibaba.tuna.netty.handler.codec.http.HttpMessage; 22 | import com.alibaba.tuna.netty.handler.codec.http.HttpObjectEncoder; 23 | 24 | /** 25 | * Encodes an RTSP message represented in {@link FullHttpMessage} into 26 | * a {@link ByteBuf}. 27 | */ 28 | @Sharable 29 | public abstract class RtspObjectEncoder extends HttpObjectEncoder { 30 | 31 | /** 32 | * Creates a new instance. 33 | */ 34 | protected RtspObjectEncoder() { 35 | } 36 | 37 | @Override 38 | public boolean acceptOutboundMessage(Object msg) throws Exception { 39 | return msg instanceof FullHttpMessage; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/EnumSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.serializer; 17 | 18 | import java.io.IOException; 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * 23 | */ 24 | public class EnumSerializer implements ObjectSerializer { 25 | 26 | public final static EnumSerializer instance = new EnumSerializer(); 27 | 28 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 29 | SerializeWriter out = serializer.getWriter(); 30 | if (object == null) { 31 | serializer.getWriter().writeNull(); 32 | return; 33 | } 34 | 35 | if (serializer.isEnabled(SerializerFeature.WriteEnumUsingToString)) { 36 | Enum e = (Enum) object; 37 | serializer.write(e.toString()); 38 | } else { 39 | Enum e = (Enum) object; 40 | out.writeInt(e.ordinal()); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/HttpContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | import com.alibaba.tuna.netty.buffer.ByteBufHolder; 19 | import com.alibaba.tuna.netty.channel.ChannelPipeline; 20 | 21 | /** 22 | * An HTTP chunk which is used for HTTP chunked transfer-encoding. 23 | * {@link HttpObjectDecoder} generates {@link HttpContent} after 24 | * {@link HttpMessage} when the content is large or the encoding of the content 25 | * is 'chunked. If you prefer not to receive {@link HttpContent} in your handler, 26 | * place {@link HttpObjectAggregator} after {@link HttpObjectDecoder} in the 27 | * {@link ChannelPipeline}. 28 | */ 29 | public interface HttpContent extends HttpObject, ByteBufHolder { 30 | @Override 31 | HttpContent copy(); 32 | 33 | @Override 34 | HttpContent duplicate(); 35 | 36 | @Override 37 | HttpContent retain(); 38 | 39 | @Override 40 | HttpContent retain(int increment); 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/CalendarCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 9 | import com.alibaba.tuna.fastjson.parser.JSONToken; 10 | import com.alibaba.tuna.fastjson.parser.deserializer.DateDeserializer; 11 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 12 | 13 | public class CalendarCodec implements ObjectSerializer, ObjectDeserializer { 14 | 15 | public final static CalendarCodec instance = new CalendarCodec(); 16 | 17 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 18 | Calendar calendar = (Calendar) object; 19 | Date date = calendar.getTime(); 20 | serializer.write(date); 21 | } 22 | 23 | @SuppressWarnings("unchecked") 24 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { 25 | Object value = DateDeserializer.instance.deserialze(parser, type, fieldName); 26 | 27 | if (value instanceof Calendar) { 28 | return (T) value; 29 | } 30 | 31 | Date date = (Date) value; 32 | if (date == null) { 33 | return null; 34 | } 35 | 36 | Calendar calendar = Calendar.getInstance(); 37 | calendar.setTime(date); 38 | 39 | return (T) calendar; 40 | } 41 | 42 | public int getFastMatchToken() { 43 | return JSONToken.LITERAL_INT; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/SerialContext.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | public class SerialContext { 4 | 5 | private final SerialContext parent; 6 | 7 | private final Object object; 8 | 9 | private final Object fieldName; 10 | 11 | private int features; 12 | 13 | private int fieldFeatures; 14 | 15 | public SerialContext(SerialContext parent, Object object, Object fieldName, int features, int fieldFeatures){ 16 | this.parent = parent; 17 | this.object = object; 18 | this.fieldName = fieldName; 19 | this.features = features; 20 | this.fieldFeatures = fieldFeatures; 21 | } 22 | 23 | public SerialContext getParent() { 24 | return parent; 25 | } 26 | 27 | public Object getObject() { 28 | return object; 29 | } 30 | 31 | public Object getFieldName() { 32 | return fieldName; 33 | } 34 | 35 | public String getPath() { 36 | if (parent == null) { 37 | return "$"; 38 | } else { 39 | if (fieldName instanceof Integer) { 40 | return parent.getPath() + "[" + fieldName + "]"; 41 | } else { 42 | return parent.getPath() + "." + fieldName; 43 | } 44 | 45 | } 46 | } 47 | 48 | public String toString() { 49 | return getPath(); 50 | } 51 | 52 | public int getFeatures() { 53 | return features; 54 | } 55 | 56 | public boolean isEnabled(SerializerFeature feature) { 57 | return SerializerFeature.isEnabled(features, fieldFeatures, feature); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/util/concurrent/BlockingOperationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.util.concurrent; 17 | 18 | /** 19 | * An {@link IllegalStateException} which is raised when a user performed a blocking operation 20 | * when the user is in an event loop thread. If a blocking operation is performed in an event loop 21 | * thread, the blocking operation will most likely enter a dead lock state, hence throwing this 22 | * exception. 23 | */ 24 | public class BlockingOperationException extends IllegalStateException { 25 | 26 | private static final long serialVersionUID = 2462223247762460301L; 27 | 28 | public BlockingOperationException() { } 29 | 30 | public BlockingOperationException(String s) { 31 | super(s); 32 | } 33 | 34 | public BlockingOperationException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | public BlockingOperationException(String message, Throwable cause) { 39 | super(message, cause); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/annotation/JSONField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2101 Alibaba Group. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.alibaba.tuna.fastjson.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | import com.alibaba.tuna.fastjson.parser.Feature; 24 | import com.alibaba.tuna.fastjson.serializer.SerializerFeature; 25 | 26 | /** 27 | * 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) 31 | public @interface JSONField { 32 | /** 33 | * config encode/decode ordinal 34 | * @since 1.1.42 35 | * @return 36 | */ 37 | int ordinal() default 0; 38 | 39 | String name() default ""; 40 | 41 | String format() default ""; 42 | 43 | boolean serialize() default true; 44 | 45 | boolean deserialize() default true; 46 | 47 | SerializerFeature[] serialzeFeatures() default {}; 48 | 49 | Feature[] parseFeatures() default {}; 50 | } 51 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/channel/socket/nio/ProtocolFamilyConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.channel.socket.nio; 17 | 18 | import java.net.ProtocolFamily; 19 | import java.net.StandardProtocolFamily; 20 | 21 | import com.alibaba.tuna.netty.channel.socket.InternetProtocolFamily; 22 | 23 | /** 24 | * Helper class which convert the {@link InternetProtocolFamily}. 25 | */ 26 | final class ProtocolFamilyConverter { 27 | 28 | private ProtocolFamilyConverter() { 29 | // Utility class 30 | } 31 | 32 | /** 33 | * Convert the {@link InternetProtocolFamily}. This MUST only be called on jdk version >= 7. 34 | */ 35 | public static ProtocolFamily convert(InternetProtocolFamily family) { 36 | switch (family) { 37 | case IPv4: 38 | return StandardProtocolFamily.INET; 39 | case IPv6: 40 | return StandardProtocolFamily.INET6; 41 | default: 42 | throw new IllegalArgumentException(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/http/HttpResponseEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.http; 17 | 18 | import com.alibaba.tuna.netty.buffer.ByteBuf; 19 | 20 | import static com.alibaba.tuna.netty.handler.codec.http.HttpConstants.*; 21 | 22 | /** 23 | * Encodes an {@link HttpResponse} or an {@link HttpContent} into 24 | * a {@link ByteBuf}. 25 | */ 26 | public class HttpResponseEncoder extends HttpObjectEncoder { 27 | private static final byte[] CRLF = { CR, LF }; 28 | 29 | @Override 30 | public boolean acceptOutboundMessage(Object msg) throws Exception { 31 | return super.acceptOutboundMessage(msg) && !(msg instanceof HttpRequest); 32 | } 33 | 34 | @Override 35 | protected void encodeInitialLine(ByteBuf buf, HttpResponse response) throws Exception { 36 | response.getProtocolVersion().encode(buf); 37 | buf.writeByte(SP); 38 | response.getStatus().encode(buf); 39 | buf.writeBytes(CRLF); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/parser/deserializer/CharArrayDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.parser.deserializer; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.alibaba.tuna.fastjson.JSON; 6 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 7 | import com.alibaba.tuna.fastjson.parser.JSONLexer; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | 10 | public class CharArrayDeserializer implements ObjectDeserializer { 11 | 12 | public final static CharArrayDeserializer instance = new CharArrayDeserializer(); 13 | 14 | @SuppressWarnings("unchecked") 15 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 16 | return (T) deserialze(parser); 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public static T deserialze(DefaultJSONParser parser) { 21 | final JSONLexer lexer = parser.getLexer(); 22 | if (lexer.token() == JSONToken.LITERAL_STRING) { 23 | String val = lexer.stringVal(); 24 | lexer.nextToken(JSONToken.COMMA); 25 | return (T) val.toCharArray(); 26 | } 27 | 28 | if (lexer.token() == JSONToken.LITERAL_INT) { 29 | Number val = lexer.integerValue(); 30 | lexer.nextToken(JSONToken.COMMA); 31 | return (T) val.toString().toCharArray(); 32 | } 33 | 34 | Object value = parser.parse(); 35 | 36 | if (value == null) { 37 | return null; 38 | } 39 | 40 | return (T) JSON.toJSONString(value).toCharArray(); 41 | } 42 | 43 | public int getFastMatchToken() { 44 | return JSONToken.LITERAL_STRING; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/fastjson/serializer/LocaleCodec.java: -------------------------------------------------------------------------------- 1 | package com.alibaba.tuna.fastjson.serializer; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Type; 5 | import java.util.Locale; 6 | 7 | import com.alibaba.tuna.fastjson.parser.DefaultJSONParser; 8 | import com.alibaba.tuna.fastjson.parser.JSONToken; 9 | import com.alibaba.tuna.fastjson.parser.deserializer.ObjectDeserializer; 10 | 11 | public class LocaleCodec implements ObjectSerializer, ObjectDeserializer { 12 | 13 | public final static LocaleCodec instance = new LocaleCodec(); 14 | 15 | public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { 16 | if (object == null) { 17 | serializer.writeNull(); 18 | return; 19 | } 20 | 21 | Locale locale = (Locale) object; 22 | serializer.write(locale.toString()); 23 | } 24 | 25 | @SuppressWarnings("unchecked") 26 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { 27 | String text = (String) parser.parse(); 28 | 29 | if (text == null) { 30 | return null; 31 | } 32 | 33 | String[] items = text.split("_"); 34 | 35 | if (items.length == 1) { 36 | return (T) new Locale(items[0]); 37 | } 38 | 39 | if (items.length == 2) { 40 | return (T) new Locale(items[0], items[1]); 41 | } 42 | 43 | return (T) new Locale(items[0], items[1], items[2]); 44 | } 45 | 46 | public int getFastMatchToken() { 47 | return JSONToken.LITERAL_STRING; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/codec/serialization/CachingClassResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.codec.serialization; 17 | 18 | import java.util.Map; 19 | 20 | class CachingClassResolver implements ClassResolver { 21 | 22 | private final Map> classCache; 23 | private final ClassResolver delegate; 24 | 25 | CachingClassResolver(ClassResolver delegate, Map> classCache) { 26 | this.delegate = delegate; 27 | this.classCache = classCache; 28 | } 29 | 30 | @Override 31 | public Class resolve(String className) throws ClassNotFoundException { 32 | // Query the cache first. 33 | Class clazz; 34 | clazz = classCache.get(className); 35 | if (clazz != null) { 36 | return clazz; 37 | } 38 | 39 | // And then try to load. 40 | clazz = delegate.resolve(className); 41 | 42 | classCache.put(className, clazz); 43 | return clazz; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /tuna-java-sdk/src/main/java/com/alibaba/tuna/netty/handler/ssl/NotSslRecordException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Netty Project 3 | * 4 | * The Netty Project licenses this file to you under the Apache License, 5 | * version 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at: 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.alibaba.tuna.netty.handler.ssl; 17 | 18 | import javax.net.ssl.SSLException; 19 | 20 | /** 21 | * Special {@link SSLException} which will get thrown if a packet is 22 | * received that not looks like a TLS/SSL record. A user can check for 23 | * this {@link NotSslRecordException} and so detect if one peer tries to 24 | * use secure and the other plain connection. 25 | * 26 | * 27 | */ 28 | public class NotSslRecordException extends SSLException { 29 | 30 | private static final long serialVersionUID = -4316784434770656841L; 31 | 32 | public NotSslRecordException() { 33 | super(""); 34 | } 35 | 36 | public NotSslRecordException(String message) { 37 | super(message); 38 | } 39 | 40 | public NotSslRecordException(Throwable cause) { 41 | super(cause); 42 | } 43 | 44 | public NotSslRecordException(String message, Throwable cause) { 45 | super(message, cause); 46 | } 47 | 48 | } 49 | --------------------------------------------------------------------------------