~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/nio/ch/SelectionKeyImpl.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002, 2003, 2004, 2005, 2006 Jeroen Frijters
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
*/
 
24
package sun.nio.ch;
 
25
 
 
26
import java.nio.channels.CancelledKeyException;
 
27
import java.nio.channels.SelectableChannel;
 
28
import java.nio.channels.SelectionKey;
 
29
import java.nio.channels.Selector;
 
30
import java.nio.channels.spi.AbstractSelectionKey;
 
31
 
 
32
final class SelectionKeyImpl extends AbstractSelectionKey
 
33
{
 
34
    final SelChImpl channel;
 
35
    final SelectorImpl selector;
 
36
    private final cli.System.Net.Sockets.Socket socket;
 
37
    private int readyOps;
 
38
    private volatile int interestOps;
 
39
 
 
40
    SelectionKeyImpl(SelChImpl ch, SelectorImpl sel)
 
41
    {
 
42
        this.channel  = ch;
 
43
        this.selector = sel;
 
44
        socket = ch.getFD().getSocket();
 
45
    }
 
46
 
 
47
    public SelectableChannel channel()
 
48
    {
 
49
        return (SelectableChannel)channel;
 
50
    }
 
51
 
 
52
    public int readyOps()
 
53
    {
 
54
        if (!isValid())
 
55
            throw new CancelledKeyException();
 
56
    
 
57
        return readyOps;
 
58
    }
 
59
 
 
60
    void readyOps(int ops)
 
61
    {
 
62
        readyOps = ops;
 
63
    }
 
64
 
 
65
    public synchronized int interestOps()
 
66
    {
 
67
        if (!isValid())
 
68
            throw new CancelledKeyException();
 
69
    
 
70
        return interestOps;    
 
71
    }
 
72
 
 
73
    public synchronized SelectionKey interestOps(int ops)
 
74
    {
 
75
        if (!isValid())
 
76
            throw new CancelledKeyException();
 
77
 
 
78
        if ((ops & ~channel.validOps()) != 0)
 
79
            throw new IllegalArgumentException();
 
80
    
 
81
        interestOps = ops;
 
82
        return this;
 
83
    }
 
84
    
 
85
    public Selector selector()
 
86
    {
 
87
        return selector;
 
88
    }
 
89
 
 
90
    cli.System.Net.Sockets.Socket getSocket()
 
91
    {
 
92
        return socket;
 
93
    }
 
94
 
 
95
    void nioReadyOps(int ops)
 
96
    {
 
97
        readyOps = ops;
 
98
    }
 
99
 
 
100
    int nioReadyOps()
 
101
    {
 
102
        return readyOps;
 
103
    }
 
104
 
 
105
    int nioInterestOps()
 
106
    {
 
107
        return interestOps;
 
108
    }
 
109
 
 
110
    SelectionKey nioInterestOps(int ops)
 
111
    {
 
112
        if ((ops & ~channel().validOps()) != 0)
 
113
            throw new IllegalArgumentException();
 
114
        channel.translateAndSetInterestOps(ops, this);
 
115
        interestOps = ops;
 
116
        return this;
 
117
    }
 
118
}