org.mortbay.jetty.LocalConnector Maven / Gradle / Ivy
//========================================================================
//Copyright 2006 Mort Bay Consulting Pty. Ltd.
//------------------------------------------------------------------------
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//http://www.apache.org/licenses/LICENSE-2.0
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//========================================================================
package org.mortbay.jetty;
import java.io.IOException;
import org.mortbay.io.Buffer;
import org.mortbay.io.ByteArrayBuffer;
import org.mortbay.io.ByteArrayEndPoint;
public class LocalConnector extends AbstractConnector
{
ByteArrayEndPoint _endp;
ByteArrayBuffer _in;
ByteArrayBuffer _out;
Server _server;
boolean _accepting;
boolean _keepOpen;
public LocalConnector()
{
setPort(1);
}
/* ------------------------------------------------------------ */
public Object getConnection()
{
return _endp;
}
/* ------------------------------------------------------------ */
public void setServer(Server server)
{
super.setServer(server);
this._server=server;
}
/* ------------------------------------------------------------ */
public void clear()
{
_in.clear();
_out.clear();
}
/* ------------------------------------------------------------ */
public void reopen()
{
_in.clear();
_out.clear();
_endp = new ByteArrayEndPoint();
_endp.setIn(_in);
_endp.setOut(_out);
_endp.setGrowOutput(true);
_accepting=false;
}
/* ------------------------------------------------------------ */
public void doStart()
throws Exception
{
_in=new ByteArrayBuffer(8192);
_out=new ByteArrayBuffer(8192);
_endp = new ByteArrayEndPoint();
_endp.setIn(_in);
_endp.setOut(_out);
_endp.setGrowOutput(true);
_accepting=false;
super.doStart();
}
/* ------------------------------------------------------------ */
public String getResponses(String requests)
throws Exception
{
return getResponses(requests,false);
}
/* ------------------------------------------------------------ */
public String getResponses(String requests, boolean keepOpen)
throws Exception
{
// System.out.println("\nREQUESTS :\n"+requests);
// System.out.flush();
ByteArrayBuffer buf=new ByteArrayBuffer(requests);
if (_in.space()0)
connection.handle();
}
finally
{
if (!_keepOpen)
{
connectionClosed(connection);
connection.destroy();
connection=null;
}
synchronized (this)
{
_accepting=false;
this.notify();
}
}
}
}
public void open() throws IOException
{
}
public void close() throws IOException
{
}
/* ------------------------------------------------------------------------------- */
public int getLocalPort()
{
return -1;
}
}