Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
tom | a708318 | 2014-09-25 21:38:03 -0700 | [diff] [blame] | 19 | package org.onlab.nio; |
| 20 | |
| 21 | import java.io.IOException; |
| 22 | import java.nio.channels.SelectionKey; |
| 23 | import java.nio.channels.Selector; |
| 24 | import java.nio.channels.spi.AbstractSelectableChannel; |
| 25 | import java.nio.channels.spi.AbstractSelector; |
| 26 | import java.util.Set; |
| 27 | |
| 28 | /** |
| 29 | * A selector instrumented for unit tests. |
| 30 | */ |
| 31 | public class MockSelector extends AbstractSelector { |
| 32 | |
| 33 | int wakeUpCount = 0; |
| 34 | |
| 35 | /** |
| 36 | * Creates a mock selector, specifying null as the SelectorProvider. |
| 37 | */ |
| 38 | public MockSelector() { |
| 39 | super(null); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public String toString() { |
| 44 | return "{MockSelector: wake=" + wakeUpCount + "}"; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected void implCloseSelector() throws IOException { |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | protected SelectionKey register(AbstractSelectableChannel ch, int ops, |
| 53 | Object att) { |
| 54 | return null; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Set<SelectionKey> keys() { |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public Set<SelectionKey> selectedKeys() { |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public int selectNow() throws IOException { |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int select(long timeout) throws IOException { |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int select() throws IOException { |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public Selector wakeup() { |
| 84 | wakeUpCount++; |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | } |