001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.nio.intraband.test;
016    
017    import com.liferay.portal.kernel.nio.intraband.Intraband;
018    import com.liferay.portal.kernel.nio.intraband.RegistrationReference;
019    
020    import java.nio.channels.GatheringByteChannel;
021    import java.nio.channels.ScatteringByteChannel;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    public class MockRegistrationReference implements RegistrationReference {
027    
028            public MockRegistrationReference(Intraband intraband) {
029                    this(intraband, null, null);
030            }
031    
032            public MockRegistrationReference(
033                    ScatteringByteChannel scatteringByteChannel,
034                    GatheringByteChannel gatheringByteChannel) {
035    
036                    this(null, scatteringByteChannel, gatheringByteChannel);
037            }
038    
039            @Override
040            public void cancelRegistration() {
041                    _cancelled = true;
042            }
043    
044            public GatheringByteChannel getGatheringByteChannel() {
045                    return _gatheringByteChannel;
046            }
047    
048            @Override
049            public Intraband getIntraband() {
050                    return _intraband;
051            }
052    
053            public ScatteringByteChannel getScatteringByteChannel() {
054                    return _scatteringByteChannel;
055            }
056    
057            @Override
058            public boolean isValid() {
059                    return !_cancelled;
060            }
061    
062            private MockRegistrationReference(
063                    Intraband intraband, ScatteringByteChannel scatteringByteChannel,
064                    GatheringByteChannel gatherByteChannel) {
065    
066                    _intraband = intraband;
067                    _scatteringByteChannel = scatteringByteChannel;
068                    _gatheringByteChannel = gatherByteChannel;
069            }
070    
071            private boolean _cancelled;
072            private final GatheringByteChannel _gatheringByteChannel;
073            private final Intraband _intraband;
074            private final ScatteringByteChannel _scatteringByteChannel;
075    
076    }