Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add javadoc for dubbo-serialization module(#3002). #3004

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
*/
package org.apache.dubbo.common.serialize;

/**
* Interface defines that the object is cleanable.
*/
public interface Cleanable {

/**
* Implementations must implement this cleanup method
*/
void cleanup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;

/**
* Data input.
* Basic data type input interface.
*/
public interface DataInput {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;

/**
* Data output.
* Basic data type output interface.
*/
public interface DataOutput {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,37 @@
import java.lang.reflect.Type;

/**
* Object input.
* Object input interface.
*/
public interface ObjectInput extends DataInput {

/**
* read object.
* read object
*
* @return object.
* @return object
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if an ClassNotFoundException occurs
*/
Object readObject() throws IOException, ClassNotFoundException;

/**
* read object.
* read object
*
* @param cls object type.
* @return object.
* @param cls object class
* @return object
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if an ClassNotFoundException occurs
*/
<T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException;

/**
* read object.
* read object
*
* @param cls object type.
* @return object.
* @param cls object class
* @param type object type
* @return object
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if an ClassNotFoundException occurs
*/
<T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;

/**
* Object output.
* Object output interface.
*/
public interface ObjectOutput extends DataOutput {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,32 @@
import java.io.OutputStream;

/**
* Serialization. (SPI, Singleton, ThreadSafe)
* Serialization strategy interface that specifies a serializer. (SPI, Singleton, ThreadSafe)
*
* The default extension is hessian2 and the default serialization implementation of the dubbo protocol.
* <pre>
* e.g. &lt;dubbo:protocol serialization="xxx" /&gt;
* </pre>
*/
@SPI("hessian2")
public interface Serialization {

/**
* get content type id
* Get content type unique id, recommended that custom implementations use values greater than 20.
*
* @return content type id
*/
byte getContentTypeId();

/**
* get content type
* Get content type
*
* @return content type
*/
String getContentType();

/**
* create serializer
* Get a serialization implementation instance
*
* @param url
* @param output
Expand All @@ -56,7 +61,7 @@ public interface Serialization {
ObjectOutput serialize(URL url, OutputStream output) throws IOException;

/**
* create deserializer
* Get a deserialization implementation instance
*
* @param url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need doc for every param.
:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my mistake

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

* @param input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Provide a unified serialization registry
*/
public abstract class SerializableClassRegistry {


private static final Map<Class, Object> registrations = new LinkedHashMap<>();

/**
* only supposed to be called at startup time
*
* @param clazz object type
*/
public static void registerClass(Class clazz) {
registerClass(clazz, null);
}

/**
* only supposed to be called at startup time
*
* @param clazz object type
* @param serializer object serializer
*/
public static void registerClass(Class clazz, Serializer serializer) {
if (clazz == null) {
Expand All @@ -43,6 +51,11 @@ public static void registerClass(Class clazz, Serializer serializer) {
registrations.put(clazz, serializer);
}

/**
* get registered classes
*
* @return class serializer
* */
public static Map<Class, Object> getRegisteredClasses() {
return registrations;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
import java.util.Collection;

/**
* This class can be replaced with the contents in config file, but for now I think the class is easier to write
*
* Interface defining serialization optimizer
*/
public interface SerializationOptimizer {

/**
* Get serializable classes
*
* @return serializable classes
* */
Collection<Class> getSerializableClasses();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import java.io.Reader;
import java.lang.reflect.Type;

/**
* FastJson object input implementation
*/
public class FastJsonObjectInput implements ObjectInput {

private final BufferedReader reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.io.PrintWriter;
import java.io.Writer;

/**
* FastJson object output implementation
*/
public class FastJsonObjectOutput implements ObjectOutput {

private final PrintWriter writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* FastJson serialization implementation
*
* <pre>
* e.g. &lt;dubbo:protocol serialization="fastjson" /&gt;
* </pre>
*/
public class FastJsonSerialization implements Serialization {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* Fst object input/output factory
*/
public class FstFactory {

private static final FstFactory factory = new FstFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import java.io.InputStream;
import java.lang.reflect.Type;


/**
* Fst object input implementation
*/
public class FstObjectInput implements ObjectInput {

private FSTObjectInput input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.io.IOException;
import java.io.OutputStream;


/**
* Fst object output implementation
*/
public class FstObjectOutput implements ObjectOutput {

private FSTObjectOutput output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* Fst serialization implementation
*
* <pre>
* e.g. &lt;dubbo:protocol serialization="fst" /&gt;
* </pre>
*/
public class FstSerialization implements Serialization {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.lang.reflect.Type;

/**
* Hessian2 Object input.
* Hessian2 object input implementation
*/
public class Hessian2ObjectInput implements ObjectInput {
private final Hessian2Input mH2i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.io.OutputStream;

/**
* Hessian2 Object output.
* Hessian2 object output implementation
*/
public class Hessian2ObjectOutput implements ObjectOutput {
private final Hessian2Output mH2o;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* Hessian2 serialization implementation, hessian2 is the default serialization protocol for dubbo
*
* <pre>
* e.g. &lt;dubbo:protocol serialization="hessian2" /&gt;
* </pre>
*/
public class Hessian2Serialization implements Serialization {

public static final byte ID = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* Compacted java serialization implementation
*
* <pre>
* e.g. &lt;dubbo:protocol serialization="compactedjava" /&gt;
* </pre>
*/
public class CompactedJavaSerialization implements Serialization {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.io.StreamCorruptedException;

/**
* Compacted java object input stream.
* Compacted java object input implementation
*/
public class CompactedObjectInputStream extends ObjectInputStream {
private ClassLoader mClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.OutputStream;

/**
* Compacted java object output stream.
* Compacted java object output implementation
*/
public class CompactedObjectOutputStream extends ObjectOutputStream {
public CompactedObjectOutputStream(OutputStream out) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.lang.reflect.Type;

/**
* Java Object input.
* Java object input implementation
*/
public class JavaObjectInput extends NativeJavaObjectInput {
public final static int MAX_BYTE_ARRAY_LENGTH = 8 * 1024 * 1024;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.OutputStream;

/**
* Java Object output.
* Java object output implementation
*/
public class JavaObjectOutput extends NativeJavaObjectOutput {
public JavaObjectOutput(OutputStream os) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import java.io.InputStream;
import java.io.OutputStream;

/**
* Java serialization implementation
*
* <pre>
* e.g. &lt;dubbo:protocol serialization="java" /&gt;
* </pre>
*/
public class JavaSerialization implements Serialization {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.io.ObjectInputStream;
import java.lang.reflect.Type;

/**
* Native java object input implementation
*/
public class NativeJavaObjectInput implements ObjectInput {

private final ObjectInputStream inputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.io.ObjectOutputStream;
import java.io.OutputStream;

/**
* Native java object output implementation
*/
public class NativeJavaObjectOutput implements ObjectOutput {

private final ObjectOutputStream outputStream;
Expand Down
Loading