summaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/RoutableFactory.java
blob: 7baa41e5c6a2a4ff30a01eba96090baea13573b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi.messagebus.protocol;

import com.yahoo.document.serialization.DocumentDeserializer;
import com.yahoo.document.serialization.DocumentSerializer;
import com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet;
import com.yahoo.messagebus.Routable;

/**
 * <p>This interface defines the necessary methods of a routable factory that can be plugged into a {@link
 * DocumentProtocol} using the {@link DocumentProtocol#putRoutableFactory(int, RoutableFactory,
 * com.yahoo.component.VersionSpecification)} method. </p>
 *
 * <p>Notice that no routable type is passed to the
 * {@link #decode(DocumentDeserializer, com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet)} method, so
 * you may NOT share a factory across multiple routable types. To share serialization logic between factory use a common
 * superclass or composition with a common serialization utility.</p>
 *
 * @author Simon Thoresen Hult
 */
public interface RoutableFactory {

    /**
     * <p>This method encodes the content of the given routable into a byte buffer that can later be decoded using the
     * {@link #decode(DocumentDeserializer)} method.</p> <p>Return false to signal failure.</p>
     * <p>This method is NOT exception safe.</p>
     *
     * @param obj The routable to encode.
     * @param out The buffer to write into.
     * @return True if the routable could be encoded.
     */
    boolean encode(Routable obj, DocumentSerializer out);

    /**
     * <p>This method decodes the given byte bufer to a routable.</p> <p>Return false to signal failure.</p> <p>This
     * method is NOT exception safe.</p>
     *
     * @param in        The buffer to read from.
     * @param loadTypes The LoadTypeSet to inject into the Routable.
     * @return The decoded routable.
     * @deprecated load types are deprecated. Use method without LoadTypeSet instead
     */
    @Deprecated(forRemoval = true) // TODO: Remove on Vespa 8
    @SuppressWarnings("removal") // TODO: Remove on Vespa 8
    Routable decode(DocumentDeserializer in, LoadTypeSet loadTypes);

    @SuppressWarnings("removal") // TODO: Remove on Vespa 8
    default Routable decode(DocumentDeserializer in) {
        return decode(in, LoadTypeSet.EMPTY);
    }

}