/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2004 The Apache Software Foundation
*
* 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
*
*
* 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.
*/
/** Pass messages using jni
*
* @author Costin Manolache
*/
public ChannelJni() {
// we use static for now, it's easier on the C side.
// Easy to change after we get everything working
}
super.initNative("channel.jni:jni");
// We'll be called from C. This deals with that.
}
}
/** Receives does nothing - send will put the response
* in the same buffer
*/
throws IOException
{
if( sentResponse == null ) {
// No sent() was done prior to receive.
sentResponse = msg;
}
if( msg != sentResponse ) {
log.severe( "Error, in JNI mode the msg used for receive() must be identical with the one used for send()");
}
return 0;
}
/** Send the packet. XXX This will modify msg !!!
* We could use 2 packets, or sendAndReceive().
*
*/
throws IOException
{
// nativeDispatch will put the response in the same buffer.
// Next receive() will just get it from there. Very tricky to do
// things in one thread instead of 2.
return rc;
}
return OK;
}
return true;
}
// Not supported.
}
return getName();
}
/** Receive a packet from the C side. This is called from the C
* code using invocation, but only for the first packet - to avoid
* recursivity and thread problems.
*
* This may look strange, but seems the best solution for the
* problem ( the problem is that we don't have 'continuation' ).
*
* sendPacket will move the thread execution on the C side, and
* return when another packet is available. For packets that
* are one way it'll return after it is processed too ( having
* 2 threads is far more expensive ).
*
* Again, the goal is to be efficient and behave like all other
* Channels ( so the rest of the code can be shared ). Playing with
* java objects on C is extremely difficult to optimize and do
* right ( IMHO ), so we'll try to keep it simple - byte[] passing,
* the conversion done in java ( after we know the encoding and
* if anyone asks for it - same lazy behavior as in 3.3 ).
*/
switch( type ) {
case JkHandler.HANDLE_SEND_PACKET:
case JkHandler.HANDLE_FLUSH:
}
// Reset receivedNote. It'll be visible only after a SEND and before a receive.
// Default is FORWARD - called from C
try {
// first, we need to get an endpoint. It should be
// The endpoint will store the message pt.
msg.processHeader();
return status;
}
return 0;
}
}