|
| 1 | +package com.barista.socket; |
| 2 | + |
| 3 | +import java.io.InputStream; |
| 4 | +import java.io.OutputStream; |
| 5 | +import java.net.InetAddress; |
| 6 | +import java.net.Proxy; |
| 7 | +import java.net.Socket; |
| 8 | +import java.net.SocketAddress; |
| 9 | +import java.net.SocketOption; |
| 10 | + |
| 11 | +import liquidjava.specification.Refinement; |
| 12 | +import liquidjava.specification.RefinementAlias; |
| 13 | +import liquidjava.specification.StateSet; |
| 14 | +import liquidjava.specification.StateRefinement; |
| 15 | +import liquidjava.specification.ExternalRefinementsFor; |
| 16 | + |
| 17 | +@StateSet({"unconnected", "binded", "connected", "closed"}) |
| 18 | +@RefinementAlias("Positive(int x) {x >= 0}") |
| 19 | +@ExternalRefinementsFor("java.net.Socket") |
| 20 | +public interface SocketRefinements { |
| 21 | + |
| 22 | + // Constructors |
| 23 | + @StateRefinement(to="unconnected(this)") |
| 24 | + public void Socket(); |
| 25 | + |
| 26 | + @StateRefinement(to="unconnected(this)") |
| 27 | + public void Socket(Proxy proxy); |
| 28 | + |
| 29 | + @StateRefinement(to="connected(this)") |
| 30 | + public void Socket(String host, @Refinement("Positive(_)") int port); |
| 31 | + |
| 32 | + @StateRefinement(to="connected(this)") |
| 33 | + public void Socket(String host, @Refinement("Positive(_)") int port, InetAddress localAddr, @Refinement("Positive(_)") int localPort); |
| 34 | + |
| 35 | + @StateRefinement(to="connected(this)") |
| 36 | + public void Socket(InetAddress address, @Refinement("Positive(_)") int port, InetAddress localAddr, @Refinement("Positive(_)") int localPort); |
| 37 | + |
| 38 | + // Methods |
| 39 | + @StateRefinement(from="unconnected(this)", to="binded(this)") |
| 40 | + public void bind(SocketAddress bindpoint); |
| 41 | + |
| 42 | + @StateRefinement(from="unconnected(this)", to="unconnected(this)") |
| 43 | + @StateRefinement(from="binded(this)", to="binded(this)") |
| 44 | + public void setPerformancePreferences(int connectionTime, int latency, int bandwith); |
| 45 | + |
| 46 | + @StateRefinement(from="unconnected(this)", to="unconnected(this)") |
| 47 | + @StateRefinement(from="binded(this)", to="binded(this)") |
| 48 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 49 | + public <T> Socket setOption(SocketOption<T> name, T value); |
| 50 | + |
| 51 | + @StateRefinement(from="unconnected(this)", to="unconnected(this)") |
| 52 | + @StateRefinement(from="binded(this)", to="binded(this)") |
| 53 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 54 | + public <T> T getOption(SocketOption<T> name); |
| 55 | + |
| 56 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 57 | + public InputStream getInputStream(); |
| 58 | + |
| 59 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 60 | + public OutputStream getOutputStream(); |
| 61 | + |
| 62 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 63 | + public void sendUrgentData(int data); |
| 64 | + |
| 65 | + @StateRefinement(from="unconnected(this) || binded(this)", to="connected(this)") |
| 66 | + public void connect(SocketAddress endpoint); |
| 67 | + |
| 68 | + @StateRefinement(from="unconnected(this) || binded(this)", to="connected(this)") |
| 69 | + public void connect(SocketAddress endpoint, @Refinement("Positive(_)") int timeout); |
| 70 | + |
| 71 | + @StateRefinement(from="unconnected(this)", to="unconnected(this)") |
| 72 | + @StateRefinement(from="binded(this)", to="binded(this)") |
| 73 | + @StateRefinement(from="connected(this)", to="connected(this)") |
| 74 | + public void setSoLinger(boolean on, @Refinement("Positive(_)") int linger); |
| 75 | + |
| 76 | + @StateRefinement(from="unconnected(this) || connected(this) || binded(this)", to="closed(this)") |
| 77 | + public void close(); |
| 78 | +} |
0 commit comments