blob: 9a3e7e710319de8ca3d021ce4c1f71925b13d415 (
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
|
package com.yahoo.search.dispatch;
import com.yahoo.fs4.BasicPacket;
import com.yahoo.fs4.ChannelTimeoutException;
import com.yahoo.fs4.mplex.Backend;
import com.yahoo.fs4.mplex.FS4Channel;
import com.yahoo.fs4.mplex.InvalidChannelException;
import com.yahoo.search.Query;
import java.io.Closeable;
import java.io.IOException;
import java.util.Optional;
public class CloseableChannel implements Closeable {
private FS4Channel channel;
public CloseableChannel(Backend backend) {
this.channel = backend.openChannel();
}
public void setQuery(Query query) {
channel.setQuery(query);
}
public boolean sendPacket(BasicPacket packet) throws InvalidChannelException, IOException {
return channel.sendPacket(packet);
}
public BasicPacket[] receivePackets(long timeout, int packetCount) throws InvalidChannelException, ChannelTimeoutException {
return channel.receivePackets(timeout, packetCount);
}
public Optional<Integer> distributionKey() {
return channel.distributionKey();
}
@Override
public void close() {
if (channel != null) {
channel.close();
channel = null;
}
}
}
|