TestStand Non blocking deported interface (C#)
Hi,
I wish to have a graphic interface (C#) allowing to manage TestStand (Read/Write of the variables FileGlobals, Wait/Set Notifications, ...). This interface must be active during the TestStand activity (graphic indicators of the state of the tests, allows the activation of sub-sequences, etc.), and it has to allow to use the TestStand interface (Do a break, step by step debug, watch variables, state of threads, etc....).
I start from the NI TestStand exemple "\TestStand 4.2.1\Examples\Demo\DotNet" and do some modification :
- call the constructor of the Dialog Windows with a SequeceCall New Thread
- Add Notification managment (unsing TSSyncLib, change the Dialog constructor and send my FileGlobals.Notifier variable create during the Notification Create step).
- Add a Button. When pressed, a FileGlobals variable Number is read, +1, then write, and display in a label. And another button Set a Notification.
- Add a breackpoint in the step next to the SequanceCall of the Dialog Windows
My problem is, as long as I do not close the windows, TestStand remains " running " and do not stop on my breakpoint, and do not respond when doing "Break All", edit Watch Variables, ...
If i change this.mDialog.ShowDialog() by this.mDialog.Show(), TestStand responds but the Dialog Windows report error with FileGlobals Read/Write and Notification.
Is my need workable ?
In attachment, the .seq file (TS4.2) with the generated dll, and the DotNet project.
Thanks for help ;o)
Solved!
Go to Solution.
Attachments:
ExempleTestStandDotNet.zip 855 KB
Great, it works !
I add "this.mSequenceContext.Thread.ExternallySuspended = true;" and I found the features of TestStand during the Dialog Windows.
That said, from the description of what you want to do, I thought you were going to start with one of the UI examples. If you really want to write a custom user interface, that might be a better way to go.
My need is to keep the full TestStand UI (list of variable, threads, Debug, ...) and to have an interface to interact on the execution of TestStand, but also manage other programs. When reading documentation, UI seems to be good for replacing the TestStand Interface by a custom interface, not for having two interfaces. And i don't want to spend time on coding (even if that seems no so difficult) something already existing and working well.
Thank you very much for your (very fast) help. )
Similar Messages
-
Using OCIBindDynamic with non-blocking connections
I need to use an OCI array interface for execute statements more than once per one request to server.
When I have called stored procedure or function in the non-blocking connection context using OCIBindDynamic for parameter binding, application have been crashed at random time.
I don't have any problems using default (blocking) mode.
Environment:
Oracle 8.1.7 release 3 for Windows
MS Visual C++ 6.0 compiler
Could anybody help me ?It's always possible in any read that the number of bytes read is less than the number of bytes requested. You need to keep reading until you have got everything you expected, and cope with every possible error condition on each iteration.
EJP -
Dear all,
Does anybody know whether PI/XI supports the non-blocking serialization function?
And in which version?
If not, is there any work-around?
Thanks a lot.
best regards
JingHI
Serialization plays an important role in distributing interdependent objects, especially when master data is being distributed.
IDocs can be created, sent and posted in a specified order by distributing message types serially.
Errors can then be avoided when processing inbound IDocs.
Interdependent messages can be serially distributed in the following ways:
Serialization by Object Type
Serialization by Message Type
Serialization at IDoc Level
(not for IDocs from generated BAPI-ALE interfaces)
Serialization at IDoc Level
Use
Delays in transferring IDocs may result in an IDoc containing data belonging to a specific object arriving at its destination before an "older" IDoc that contains different data belonging to the same object. Applications can use the ALE Serialization API to specify the order IDocs of the same message type are processed in and to prevent old IDocs from being posted if processing is repeated.
ALE provides two function modules to serialize IDocs which the posting function module has to invoke:
u2022 IDOC_SERIALIZATION_CHECK
checks the time stamps in the serialization field of the IDoc header.
u2022 IDOC_SERIAL_POST
updates the serialization table.
Check the following link:
http://help.sap.com/saphelp_nw04s/helpdata/en/0b/2a66d6507d11d18ee90000e8366fc2/frameset.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/78/2175a751ce11d189570000e829fbbd/frameset.htm
How to serialize IDoc XML messages fed into XI
cheers -
I'd like to use the OCCI interface in a non-blocking mode. Does anyone have any experience with this? Looks like I need to use a combo of OCI and OCCI calls to set the OCI_HTYPE_SERVER handle with the OCI_ATTR_NONBLOCKING MODE. However, my stmt->executeQuery() method seems to be throwing an exceptions, which I would have though would have been the OCI_STILL_EXECUTING error, but it's not. The exeception is an "ORA-32103 error from OCI call". If I continue to do another stmt->executeQuery(), I eventually get an access exception.
Anyone have any code snippets using OCCI in non-blocking mode?I use threads. ACE/TAO to be precise.
I have singleton class that manages the Oracle environment and connection as well as being a statement
factory.
Just have a thread perform your stmt->executeXXX() method and you will not need to worry about non-blocking.
That's how I do it and it works well. -
What is wrong with my non-blocking client?
I have two classes here, my abstract base class SingleSocketHandler, and its concrete subclass SingleSocketHandlerImpl. The subclass implements the protocol and parsing of my server.
For some reason, my server is not receiving the packet my client sends to it, and my client is getitng nothing in return (which makes sense, the server is supposed to respond to the logon packet). I make it non-blocking AFTER logon, so I knwo that this is not a problem. Can you see why my server is not receiving the packet my client writes to it? Did I not configure some setting with the SocketChannel that enables it to write? I am sort of unfamiliar with the java.nio.channels package, so the problem may be related to a setting in the SocketChannel or whatnot that I haven't configured.
NOTE: My chat server works fine with my blocking, multi-threaded test clients. Just not for my non-blocking client. The original problem for my blocking clients was that once the server stopped sending them data, they'd get caught in the in.read() loop and never get out of it. That's why I turned to non-blocking.
Just to remind you, my question is: why isn't my client sending the logon packet AND/OR my server receiving+responding to it?
public abstract class SingleSocketHandler extends Thread
/* Subclasses must implement these methods
/* Even though they're not a (public) interface */
/** <------------------------------- */
abstract void parse(int num);
abstract void parseNext();
abstract void doLogon();
/** -------------------------------> */
private SocketChannel sock;
/* Queues for in and out buffers */
private LinkedList <ByteBuffer> qIn;
private LinkedList <ByteBuffer> qOut;
/* Server info */
private String hostname;
private int port;
/* Flags */
protected int flags;
protected final int LOGGED_ON = 0x01;
* Default Constructor
protected SingleSocketHandler()
initQs();
* Constructor that sets socket info
* @param hostname
* @param port
* @param connect
protected SingleSocketHandler(String hostname, int port, boolean connect)
initQs();
if (connect)
connect(hostname, port);
else
setSocket(hostname, port);
* Switches off between reading and writing
protected void handleIO()
try
sock.configureBlocking(false);
} catch (IOException e)
// TODO
readInBuffers(1);
writeOutBuffers(1);
* Read in specified number of buffers into in queue
* Call for parsing
* @param num
protected void readInBuffers(int num)
Reporter.println("READING BUFFER");
for (int i = 0; i < num; i++)
ByteBuffer header = ByteBuffer.allocate(ProtocolCheck.HEADER_LEN);
try
Reporter.println("Reading header...");
sock.read(header);
Reporter.println("Read header.");
} catch (IOException e)
// TODO
/* Only add packet to in queue if it has a valid header */
if (ProtocolCheck.validHeader(header.array()))
Reporter.println("valid header");
ByteBuffer packet = ByteBuffer.allocate(ProtocolCheck.findPacketLen(header.array()));
packet.put(header);
try
Reporter.println("Reading rest of packet...");
sock.read(packet);
Reporter.println("Read packet.");
} catch (IOException e)
// TODO
addInBuffer(packet);
* Write out specified number of buffers from out queue
* And remove from out queue
* @param num
protected void writeOutBuffers(int num)
Reporter.println("WRITING BUFFER");
int i = 0;
while (qOut.size() > 0 && i < num)
try
sock.write(nextOutBuffer());
Reporter.println("Wrote buffer.");
} catch (IOException e)
// TODO
i++;
* Returns and removes next buffer from in queue
* @return ByteBuffer
protected ByteBuffer nextInBuffer()
return qIn.remove();
* Returns and removes next buffer from out queue
* @return ByteBuffer
protected ByteBuffer nextOutBuffer()
return qOut.remove();
* Sees if there is anohter in buffer
* @return boolean
protected boolean hasNextInBuffer()
return qIn.size() > 0;
* Sees if there is another out buffer
* @return ByteBuffer
protected boolean hasNextOutBuffer()
return qOut.size() > 0;
* Add a buffer to in queue
* @param b
public void addInBuffer(ByteBuffer b)
qIn.add(b);
* Add a buffer to in queue
* @param b
public void addInBuffer(Bufferable b)
qIn.add(b.getByteBuffer());
* Add a buffer to out queue
* @param b
public void addOutBuffer(ByteBuffer b)
qOut.add(b);
* Add a buffer to out queue
* @param b
public void addOutBuffer(Bufferable b)
qOut.add(b.getByteBuffer());
* Instantiate queues
protected void initQs()
qIn = new LinkedList <ByteBuffer> ();
qOut = new LinkedList <ByteBuffer> ();
* Set socket info then call connect()
* @param hostname
* @param port
public void connect(String hostname, int port)
setSocket(hostname, port);
connect();
* Connect to server
public void connect()
try
sock = SocketChannel.open();
sock.configureBlocking(true);
sock.connect(new InetSocketAddress(hostname, port));
while (!sock.finishConnect())
} catch (IOException e)
// TODO
* Disconnect from server
public void disconnect()
try
sock.close();
} catch (IOException e)
// TODO
* Set socket info without connecting
* @param hostname
* @param port
public void setSocket(String hostname, int port)
this.hostname = hostname;
this.port = port;
* @return state of connection
public boolean isConnected()
return (sock != null && sock.isConnected());
* @return state of being logged on
public boolean isLoggedOn()
return (sock != null && (flags & LOGGED_ON) == LOGGED_ON);
public final class SingleSocketHandlerImpl extends SingleSocketHandler
private UserDatabase <User> users;
* Constructor that does not set socket info
public SingleSocketHandlerImpl(UserDatabase <User> users)
super();
this.users = users;
* Constructor that does set socket info
* @param hostname
* @param port
* @param connect
public SingleSocketHandlerImpl(String hostname, int port, boolean connect, UserDatabase <User> users)
super(hostname, port, connect);
this.users = users;
* Thread's run method (base class extends Thread)
public void run()
doLogon();
while (isConnected() && isLoggedOn())
handleIO();
* Parses specified number of buffers from in queue
* @param num
/* (non-Javadoc)
* @see client.SingleSocketHandler#parseNext()
@Override
protected void parse(int num)
Reporter.println("Parse(int num) called.");
int i = 0;
while (hasNextInBuffer() && i < num)
parseNext();
i++;
/* (non-Javadoc)
* @see client.SingleSocketHandler#parseNext()
@Override
protected void parseNext()
Reporter.println("Parsing!");
if (!hasNextInBuffer())
Reporter.println("NO IN BUFFER.");
return;
/* Get buffer to work with */
ByteBuffer inBuffer = nextInBuffer();
byte[] data = inBuffer.array();
/* Decide what to do based on message ID */
byte msgid = data[1];
switch (msgid) {
case 0x01:
Reporter.println("0x01 packet.");
/* Determine success of login */
byte success = data[3];
if (success == (byte) 1)
flags |= LOGGED_ON;
Reporter.println("Logged on!");
else
flags &= ~LOGGED_ON;
Reporter.println(" <eChat> Unable to logon. Check the hostname and port settings.");
break;
case 0x02:
/* Parse out text message */
byte[] txtmsgbytes = new byte[data.length - 3];
System.arraycopy(data, 3, txtmsgbytes, 0, txtmsgbytes.length);
String txtmsg = new String(txtmsgbytes);
Reporter.println(txtmsg);
break;
case 0x03:
System.out.println("Packet ID not yet handled.");
break;
case 0x04:
System.out.println("Packet ID not yet handled.");
break;
default:
System.out.println("validID() method is buggy.");
* I make it non-blocking after logon sequences
/* (non-Javadoc)
* @see client.SingleSocketHandler#doLogon()
@Override
protected void doLogon()
Reporter.println("DOING LOGON!");
User myUser = users.getCurr();
addOutBuffer(new ScpLogon(myUser.getUsername(), myUser.getPassword()));
writeOutBuffers(1);
readInBuffers(1);
parseNext();
}Oh, if this helps, this is what gets output to my GUI. I did a lot of outputs for debugging purposes.
[3:29:27 PM]: Connecting...
[3:29:27 PM]: Connected!
[3:29:27 PM]: Logging on...
[3:29:27 PM]: DOING LOGON!
[3:29:27 PM]: WRITING BUFFER
[3:29:27 PM]: Wrote buffer.
[3:29:27 PM]: READING BUFFER
[3:29:27 PM]: Reading header... -
SQL Developer blocking vs non-blocking
Hi,
Is there a way in SQL Developer 3.0 to have a non-blocking SQL call? In Oracle Forms we can choose between blocking and non-blocking SQL Net connections to the database. Does SQL Developer have the same capability? If so where exactly are those options hidden in the preferences menus?
Annoyed,
ScottK
Edited by: ScottK on Jun 1, 2011 11:20 AMHi ScottK,
SQLDeveloper locks access to individual connections when they are in use, if you want to simulate
some aspects of non blocking behaviour you can use other connections.
The following features might help:
Use a different connection name back to the same schema in your database - it will be treated as an independent connection and 'blocking' on this connection will not affect your other connections.
This can be achieved temporarily in the worksheet by:
ctrl shift n
which creates a worksheet with new connection independent of your existing worksheet connection
though connected to the same schema and database.
-Turloch
SQLDeveloper team -
ORA-03118 two-task error while doing a non blocking OCI call
Hi,
I have an application that runs on Linux and uses OCI API (version 8.1.6).
If I do the following in non blocking mode after polling about
70 times I get the error:
ORA-03118: two-task coroutine has invalid state
do {
call_cnt++;
rtc = OCIStmtFetch(stmtptr->stmt, oracle_err, 1, OCI_FETCH_NEXT,
OCI_DEFAULT);
} while (rtc == OCI_STILL_EXECUTING);
This doesn't happen all the time but it happens most often on big selects.
Does anyone have any idea what is happening here?
I have searched for related information but have come up dry. If anyone
knows anything or maybe a better place to ask this question please tell me.
Thanks,
Barry
nullAsk your basis guys to increase the table space...
check this thread...
[Error : DBIF_RSQL_SQL_ERROR;
--- Thanks... -
What is the difference between non-blocking and 1:1 oversubscribed?
Could someone tell me what the difference is between a non-blocked port and one with 1:1 oversubscription?
"non-blocking port" and "1:1 oversubscription" are the same. It's also the same when you are saying "line rate".
-
Implementing non-blocking read
Hi all
I have some doubts about implementing non-blocking io in my application.
I am using Jsch library (an ssh implementation) to open an ssh connection with a host. The API only provides me with methods to open a connection and retreive the input & output streams. I want to make my read on inputstream non-blocking.In such a case is it possible to use nio for the purpose?
If it's not possible then I am planning to use threading to make read() non-blocking. Here also i need some clarifications. I am planning to use a ThreadPoolExecutor to create a thread pool for reading data. SO whenever i have a read i'll assign this task to the pool which will use one of the free threads to execute the inputStresm.read().
Now the question is if one of the threads in this pool blocks forever during a read since it didn't get any response from the other side, is there a way to stop that read and make that thread free again to execute more tasks? or will the thread block forever till the application is closed?
In my case i cannot afford to have too many such blocked threads, since this application will not be restarted very often. Once it is started it can go on for may be days or months.
Please suggest what would be best in my case taking into account performance as most important factor.
Thanks in advance.
Anuendasil wrote:
First of all, let me state that I agree with the others in saying that I don't fully agree with your premises.
That said, I believe that this does a non-blocking read based on the contract of InputStream.available() and .read(byte[], int, int):
private int nonBlockingRead(InputStream in, byte[] buffer) throws IOException {
return in.read(buffer, 0, Math.min(in.available(), buffer.length));
If the InputStream is obtained from a JSSE socket then it is my understanding that available() always returns zero. This is allowed under the InputStream.available() contract as defined in the Javadoc - http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#available() . If I am right then your code will never read anything from a JSSE socket InputStream and I would suspect that Jsch is using JSSE sockets. -
I need to include a procedure in a dll that is non-blocking, i.e. it should return immediately after the procedure has been called, and not return after its processes are completed.
The procedure is a LabView 7.0 VI, and the dll is being created using the Application Builder. Currently the procedure completes its desired task and then returns, but I would like the function to return immediately. Thanks for your help!Rischaard,
I don't know if that will work in a dll, however as an idea:
use the vi-server functions:
Your dll-procedure opens a OwnTreat.vi(wich will do the work) with vi-server, and run it without waiting for completion.
First thing OwnTreat.vi should do is opening (with vi-server) a reference to itself (So your caller dll can close without stopping the OwnTreat.vi)
Then OwnTreat.vi con do what YOU want. When finished close the self-reference
Maybe you need a short wait or a feedback to make sure that OwnTreat has opened his own reverence before your dll stops.
Greetings from Germany
Henrik
LV since v3.1
“ground” is a convenient fantasy
'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ' -
Non-blocking and terminating processes
Can someone give me an example of using the host.nonblocking to terminate a process or a window that is opened using a webutil_file_Transfer.DB_To_Client when finished using the opened document.
I am using oracle 10g developer:
Thanks"non-blocking port" and "1:1 oversubscription" are the same. It's also the same when you are saying "line rate".
-
NIO: Strange problem when using ByteBuffer with non-blocking SocketChannel
Hi,
I have a server that uses multiplexed, non-blocking I/O with java.nio. When a client connects, the server waits for the message: <system cmd="knock"/>, returns a message and disconnects the client. The clients are shortly serviced in less than a second.
But the server newer receive anything from about 20% of the clients - even though it is sent. Or with other words: it is received and the data is contained in the ByteBuffer - SocketChannel.read(ByteBuffer) - but a call to ByteBuffer.remaing() returns 0 !!
ByteBuffer receiveBuf = ByteBuffer.allocate(65536);
receiveBuf.clear(); // the code is elsewhere used for longer living clients
int readBytes = channel.read(receiveBuf);
receiveBuf.flip();
StringBuffer sb = new StringBuffer();
System.out.println(" * Remaining: "+receiveBuf.remaining()); // writes: ' * Remaining: 0'
System.out.println(" * Received: "+new String(receiveBuf.array())); // writes: ' * Received: <system cmd="knock"/>'
while(receiveBuf.remaining() >= 2) {
byte b = receiveBuf.get();
sb.append((char)b);
System.out.println(" * sb content: "+sb.toString()); // writes: ' * sb content: 'The ByteBuffer clearly receives the correct data, but the ByteBuffer.remaining() returns 0 and therefore the StringBuffer will never have any content.
The problem seems to occur randomly and for about 20% of the clients (simulated from the same computer and therefore has the same bandwidth and so on).
Anyone knows what is going on, and how to solve the problem !?It's always possible in any read that the number of bytes read is less than the number of bytes requested. You need to keep reading until you have got everything you expected, and cope with every possible error condition on each iteration.
EJP -
SELECT of OCILobLocator in Non Blocking mode
Hi all.
I have problem:
I try select BLOB field into OCILobLocator* buffer in Non Blocking mode, and receive 'ORA-03106: fatal two-task communication protocol error' sometimes.
Details:
Application contains two threads : 1. select blob field, 2. update it.
I tried separate update and select to different apps (and run its in one time) - problem reproduced.
problem reproduced for OCIStmtFetch and OCIStmtFetch2.
If disable non blocking mode - problem disappear.
if error appear - record level error code contains 1405. Need wait few minutes for error message appearing (~1 minute in my case).
Using of OCI_DEFAULT in OCIDefineByPos instead OCI_DYNAMIC_FETCH don't solve problem.
I use oracle server and client library with version 10.2.0.4
Output sample:
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #877: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #54: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #877: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #54: 1405
Can anybody help me ?
m.b. exists workaround ?
#include <iostream>
#include <sstream>
#include <assert.h>
#include <oci.h>
#define _DYN 1
before run this test run next sql at DB:
CREATE TABLE ADSERVERTEST_BLOB(id NUMBER(10), text BLOB);
BEGIN
FOR i IN 0..999 LOOP
INSERT INTO ADSERVERTEST_BLOB(id, text) VALUES(i, utl_raw.cast_to_raw('init'));
END LOOP;
END;
template<typename Type, unsigned long TypeId>
class OCIHandlePtr
public:
OCIHandlePtr(): handle_(0) {}
OCIHandlePtr(Type* handle): handle_(handle) {}
~OCIHandlePtr()
reset(0);
void reset(Type* handle)
if(handle_)
sword result;
if((result = OCIHandleFree(
handle_,
TypeId)) != OCI_SUCCESS)
assert(0);
std::cerr << "Can't make OCIHandleFree" << std::endl;
handle_ = handle;
Type* get()
return handle_;
Type*& fill()
reset(0);
return handle_;
private:
Type* handle_;
template<typename Type, unsigned long TypeId>
class OCIDescriptorPtr
public:
OCIDescriptorPtr(): handle_(0) {}
OCIDescriptorPtr(Type* handle): handle_(handle) {}
~OCIDescriptorPtr()
reset(0);
void reset(Type* handle)
if(handle_)
sword result;
if((result = OCIDescriptorFree(
handle_,
TypeId)) != OCI_SUCCESS)
std::cerr << "Can't make OCIDescriptorFree" << std::endl;
handle_ = handle;
Type* get()
return handle_;
Type*& fill()
reset(0);
return handle_;
private:
Type* handle_;
void throw_oci_error(
const char* fun,
const char* oci_op,
long status,
OCIError* oci_error_handler,
const char* query = 0)
std::cerr << fun << ": can't make " << oci_op << ": status = " << status;
if(status == OCI_SUCCESS_WITH_INFO ||
status == OCI_ERROR)
std::cerr << ", message = '";
text err_buf[1024] = "";
sb4 err_code = 0;
OCIErrorGet(
oci_error_handler,
(ub4)1,
0,
&err_code,
err_buf,
sizeof(err_buf),
(ub4)OCI_HTYPE_ERROR);
std::cerr << err_buf << "', error code = " << err_code;
exit(1);
if(query)
std::cerr << ", sql = " << query;
OCIHandlePtr<OCIEnv, OCI_HTYPE_ENV> environment_handle;
void connect(
OCIEnv* environment_handle,
const char* db,
const char* user,
const char* password,
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR>& error_handle,
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER>& server_handle,
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION>& session_handle,
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX>& svc_context_handle)
static const char* FUN = "connect()";
sword result;
// allocate an error handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &error_handle.fill(),
OCI_HTYPE_ERROR,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// allocate a server handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &server_handle.fill(),
OCI_HTYPE_SERVER,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
if((result = OCIServerAttach(
server_handle.get(),
error_handle.get(),
(text*)db,
strlen(db),
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIServerAttach", result, error_handle.get());
// allocate a service handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &svc_context_handle.fill(),
OCI_HTYPE_SVCCTX,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// set the server attribute in the service context handle
if((result = OCIAttrSet(
svc_context_handle.get(),
OCI_HTYPE_SVCCTX,
server_handle.get(),
sizeof(OCIServer*),
OCI_ATTR_SERVER,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// allocate a user session handle
if((result = OCIHandleAlloc(
environment_handle,
(void **)&session_handle.fill(),
OCI_HTYPE_SESSION,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// set username and password attributes in user session handle
if((result = OCIAttrSet(
session_handle.get(),
OCI_HTYPE_SESSION,
(text*)user,
strlen(user),
OCI_ATTR_USERNAME,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
if((result = OCIAttrSet(
session_handle.get(),
OCI_HTYPE_SESSION,
(text*)password,
strlen(password),
OCI_ATTR_PASSWORD,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
// start the session
if((result = OCISessionBegin(
svc_context_handle.get(),
error_handle.get(),
session_handle.get(),
OCI_CRED_RDBMS,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCISessionBegin", result, error_handle.get());
// set the user session attribute in the service context handle
if((result = OCIAttrSet(
svc_context_handle.get(),
OCI_HTYPE_SVCCTX,
session_handle.get(),
sizeof(OCISession*),
OCI_ATTR_SESSION,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
ub1 attr_value = 1;
if((result = OCIAttrSet(
server_handle.get(),
OCI_HTYPE_SERVER,
&attr_value,
sizeof(attr_value),
OCI_ATTR_NONBLOCKING_MODE,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
void disconnect(
OCIEnv* environment_handle,
OCIError* error_handle,
OCIServer* server_handle,
OCISession* session_handle,
OCISvcCtx* svc_context_handle)
static const char* FUN = "disconnect()";
sword result;
if((result = OCISessionEnd(
svc_context_handle,
error_handle,
session_handle,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCISessionEnd", result, error_handle);
if((result = OCIServerDetach(
server_handle,
error_handle,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIServerDetach", result, error_handle);
OCILobLocator* FETCH_BUFFER_1[10000*1024];
char IND_BUFFER_1[10000*1024];
ub2 ERROR_BUFFER_1[1024];
OCIDefine* define_handle_1;
void clear_blob_buf(
OCILobLocator** buf,
unsigned long fetch_size)
for(unsigned long i = 0; i < 1024; ++i)
OCIDescriptorFree(
buf,
(ub4)OCI_DTYPE_LOB);
::memset(buf, 0, fetch_size * 1024);
uint32_t RET_LEN4;
sb4 oci_blob_callback(
dvoid* ctx,
OCIDefine* define,
ub4 iter,
dvoid** bufpp,
ub4** alenpp,
ub1* piecep,
dvoid** indpp,
ub2** rcodepp)
RET_LEN4 = sizeof(OCILobLocator*);
*bufpp = FETCH_BUFFER_1[iter];
*alenpp = &RET_LEN4;
*piecep = OCI_ONE_PIECE;
*indpp = IND_BUFFER_1 + iter;
*rcodepp = ERROR_BUFFER_1 + iter;
//std::cout << "iter: " << iter << std::endl;
return OCI_CONTINUE;
int define_column(
OCIEnv* environment_handle,
OCISvcCtx* svc_handle,
OCIStmt* stmt_handle,
OCIError* error_handle,
OCIDefine** define_handle,
unsigned long pos,
long oci_type,
unsigned long fetch_size,
OCILobLocator** buf,
char* ind_buf,
ub2* err_buf)
static const char* FUN = "define_column()";
sword result;
if(oci_type == SQLT_BLOB)
::memset(buf, 0, fetch_size * 1024);
for(int i = 0; i < 1024; ++i)
if((result = OCIDescriptorAlloc(
(dvoid*)environment_handle,
(dvoid**)&buf[i],
(ub4)OCI_DTYPE_LOB,
(size_t)0,
(dvoid**)0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDescriptorAlloc", result, error_handle);
ub2 size = 0;
OCIDescriptorPtr<OCIParam, OCI_DTYPE_PARAM> param_handle;
// ub2 oci_data_type = 0;
if((result = OCIParamGet(
stmt_handle,
OCI_HTYPE_STMT,
error_handle,
reinterpret_cast<void**>(¶m_handle.fill()),
pos)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIParamGet", result, error_handle);
if((result = OCIAttrGet(
param_handle.get(),
OCI_DTYPE_PARAM,
&size,
0,
OCI_ATTR_DATA_SIZE,
error_handle)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle);
if((result = OCIDefineByPos(
stmt_handle,
define_handle,
error_handle,
pos,
# ifdef _DYN
0,
-1,
#else
buf,
fetch_size,
#endif
oci_type,
ind_buf,
0,
err_buf, // ptr to array of column-level return codes
# ifdef _DYN
OCI_DYNAMIC_FETCH
# else
OCI_DEFAULT
# endif
)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
# ifdef _DYN
if((result = OCIDefineDynamic(
*define_handle,
error_handle,
0,
oci_blob_callback)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
# endif
return 0;
int define_columns(
OCIEnv* environment_handle,
OCISvcCtx* svc_handle,
OCIStmt* stmt_handle,
OCIError* error_handle)
static const char* FUN = "define_columns()";
define_handle_1 = 0;
int pos = 1;
::memset(ERROR_BUFFER_1, 0, 1024 * sizeof(ERROR_BUFFER_1[0]));
define_column(
environment_handle,
svc_handle,
stmt_handle,
error_handle,
&define_handle_1,
pos++,
SQLT_BLOB,
sizeof(OCILobLocator*),
FETCH_BUFFER_1,
IND_BUFFER_1,
ERROR_BUFFER_1);
return 0;
int execute_select(
const char* db,
const char* user,
const char* password)
static const char* FUN = "execute_select()";
const unsigned long FETCH_COUNT = 1024;
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
connect(
environment_handle.get(),
db,
user,
password,
error_handle,
server_handle,
session_handle,
svc_context_handle);
OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
sword result;
if((result = OCIHandleAlloc(
environment_handle.get(),
(void**)&stmt_handle.fill(),
OCI_HTYPE_STMT,
0,
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
const char QUERY[] = "SELECT text FROM ADSERVERTEST_BLOB";
ub4 rows = 0;
if((result = OCIAttrSet(
stmt_handle.get(),
OCI_HTYPE_STMT,
(dvoid *)&rows,
(ub4)sizeof(ub4),
OCI_ATTR_PREFETCH_ROWS,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(
FUN, "OCIAttrSet(OCI_ATTR_PREFETCH_ROWS)", result, error_handle.get());
if((result = OCIStmtPrepare(
stmt_handle.get(),
error_handle.get(),
(text*)QUERY,
strlen(QUERY),
OCI_NTV_SYNTAX,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
ub2 stmt_type;
if((result = OCIAttrGet(
stmt_handle.get(),
OCI_HTYPE_STMT,
&stmt_type,
0,
OCI_ATTR_STMT_TYPE,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
ub4 prev_fetched = 0;
while((result = OCIStmtExecute(
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get(),
0,
0,
0,
0,
OCI_DEFAULT)) != OCI_SUCCESS)
if(result != OCI_STILL_EXECUTING)
throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
define_columns(
environment_handle.get(),
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get());
ub4 all_fetched_count = 0;
while(true)
while((result = OCIStmtFetch2(
stmt_handle.get(),
error_handle.get(),
FETCH_COUNT,
OCI_FETCH_NEXT,
1,
OCI_DEFAULT)) == OCI_STILL_EXECUTING
# ifdef _DYN
// || result == OCI_NEED_DATA
# endif
if (result != OCI_SUCCESS &&
result != OCI_NO_DATA &&
result != OCI_SUCCESS_WITH_INFO)
std::cerr << FUN << ": can't make OCIStmtFetch2: status = " << result;
std::cerr << ", message = '";
text err_buf[1024] = "";
sb4 err_code = 0;
OCIErrorGet(
error_handle.get(),
(ub4)1,
0,
&err_code,
err_buf,
sizeof(err_buf),
(ub4)OCI_HTYPE_ERROR);
std::cerr << err_buf << "', error code = " << err_code << ", row errors: ";
for(const ub2* cur = ERROR_BUFFER_1;
cur < ERROR_BUFFER_1 + 1024; ++cur)
if(*cur)
std::cerr << "#" << (cur - ERROR_BUFFER_1) << ": " <<
*cur << std::endl;
ub4 fetched_count = 0;
if((result = OCIAttrGet (
stmt_handle.get(),
OCI_HTYPE_STMT,
&fetched_count,
0,
OCI_ATTR_ROW_COUNT,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
all_fetched_count += fetched_count;
if(fetched_count > 0)
for(unsigned long i = 0; i < fetched_count - 1; ++i)
ub4 lob_size;
while((result = OCILobGetLength(
svc_context_handle.get(),
error_handle.get(),
FETCH_BUFFER_1[i],
&lob_size)) == OCI_STILL_EXECUTING)
if(result != OCI_SUCCESS)
throw_oci_error(FUN, "OCILobGetLength", result, error_handle.get());
std::cout << "#" << i << ": ind = " << (unsigned long)IND_BUFFER_1[i] <<
", len = " << lob_size << std::endl;
if(fetched_count - prev_fetched < FETCH_COUNT)
break;
prev_fetched = fetched_count;
clear_blob_buf(
FETCH_BUFFER_1,
sizeof(OCILobLocator*));
while((result = OCIStmtFetch(
stmt_handle.get(),
error_handle.get(),
0,
OCI_FETCH_NEXT,
OCI_DEFAULT)) == OCI_STILL_EXECUTING
disconnect(
environment_handle.get(),
error_handle.get(),
server_handle.get(),
session_handle.get(),
svc_context_handle.get());
return 0;
int execute_update(
const char* db,
const char* user,
const char* password)
static const char* FUN = "execute_update()";
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
connect(
environment_handle.get(),
db,
user,
password,
error_handle,
server_handle,
session_handle,
svc_context_handle);
OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
for(int i = 0; i < 1000; ++i)
sword result;
if((result = OCIHandleAlloc(
environment_handle.get(),
(void**)&stmt_handle.fill(),
OCI_HTYPE_STMT,
0,
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
std::ostringstream sql;
std::string str;
std::string et("\xEB\xB2\x88");
unsigned long rep = ::rand() % 500 + 1;
str.reserve(rep*et.size());
for(unsigned long ei = 0; ei < rep; ++ei)
str.append(et);
sql << "BEGIN " <<
"UPDATE ADSERVERTEST_BLOB SET text = "
"utl_raw.cast_to_raw('" << str << "') "
"WHERE id = " << i <<
"END;";
if((result = OCIStmtPrepare(
stmt_handle.get(),
error_handle.get(),
(text*)sql.str().c_str(),
sql.str().length(),
OCI_NTV_SYNTAX,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
while((result = OCIStmtExecute(
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get(),
1,
0,
0,
0,
OCI_DEFAULT)) != OCI_SUCCESS)
if(result != OCI_STILL_EXECUTING)
throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
disconnect(
environment_handle.get(),
error_handle.get(),
server_handle.get(),
session_handle.get(),
svc_context_handle.get());
return 0;
void* select_thread(void* ctx)
while(true)
execute_select(
"//oraclept.ocslab.com/addbpt.ocslab.com",
"bs_unittest_4",
"adserver");
// std::cout << "select finished" << std::endl;
return ctx;
void* update_thread(void* ctx)
while(true)
execute_update(
"//oraclept.ocslab.com/addbpt.ocslab.com",
"bs_unittest_4",
"adserver");
// std::cout << "update finished" << std::endl;
return ctx;
int main()
static const char* FUN = "main()";
sword result;
// allocate an environment handle
if((result = OCIEnvCreate(
&environment_handle.fill(),
OCI_OBJECT | OCI_THREADED,
0, // context
0, // malloc
0, // realloc
0, // free
0, // extra memory to allocate
0) // pointer to user-memory
) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIEnvCreate", result, 0);
pthread_t th1, th2;
pthread_create(&th1, 0, select_thread, 0);
pthread_create(&th2, 0, update_thread, 0);
pthread_join(th1, 0);
pthread_join(th2, 0);
return 0;
Edited by: user13011391 on 20.04.2010 5:50
Edited by: user13011391 on 20.04.2010 6:00
Edited by: user13011391 on 20.04.2010 6:15Hi all.
I have problem:
I try select BLOB field into OCILobLocator* buffer in Non Blocking mode, and receive 'ORA-03106: fatal two-task communication protocol error' sometimes.
Details:
Application contains two threads : 1. select blob field, 2. update it.
I tried separate update and select to different apps (and run its in one time) - problem reproduced.
problem reproduced for OCIStmtFetch and OCIStmtFetch2.
If disable non blocking mode - problem disappear.
if error appear - record level error code contains 1405. Need wait few minutes for error message appearing (~1 minute in my case).
Using of OCI_DEFAULT in OCIDefineByPos instead OCI_DYNAMIC_FETCH don't solve problem.
I use oracle server and client library with version 10.2.0.4
Output sample:
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #877: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #54: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #877: 1405
execute_select(): can't make OCIStmtFetch2: status = -1, message = 'ORA-03106: fatal two-task communication protocol error
', error code = 3106, row errors: #54: 1405
Can anybody help me ?
m.b. exists workaround ?
#include <iostream>
#include <sstream>
#include <assert.h>
#include <oci.h>
#define _DYN 1
before run this test run next sql at DB:
CREATE TABLE ADSERVERTEST_BLOB(id NUMBER(10), text BLOB);
BEGIN
FOR i IN 0..999 LOOP
INSERT INTO ADSERVERTEST_BLOB(id, text) VALUES(i, utl_raw.cast_to_raw('init'));
END LOOP;
END;
template<typename Type, unsigned long TypeId>
class OCIHandlePtr
public:
OCIHandlePtr(): handle_(0) {}
OCIHandlePtr(Type* handle): handle_(handle) {}
~OCIHandlePtr()
reset(0);
void reset(Type* handle)
if(handle_)
sword result;
if((result = OCIHandleFree(
handle_,
TypeId)) != OCI_SUCCESS)
assert(0);
std::cerr << "Can't make OCIHandleFree" << std::endl;
handle_ = handle;
Type* get()
return handle_;
Type*& fill()
reset(0);
return handle_;
private:
Type* handle_;
template<typename Type, unsigned long TypeId>
class OCIDescriptorPtr
public:
OCIDescriptorPtr(): handle_(0) {}
OCIDescriptorPtr(Type* handle): handle_(handle) {}
~OCIDescriptorPtr()
reset(0);
void reset(Type* handle)
if(handle_)
sword result;
if((result = OCIDescriptorFree(
handle_,
TypeId)) != OCI_SUCCESS)
std::cerr << "Can't make OCIDescriptorFree" << std::endl;
handle_ = handle;
Type* get()
return handle_;
Type*& fill()
reset(0);
return handle_;
private:
Type* handle_;
void throw_oci_error(
const char* fun,
const char* oci_op,
long status,
OCIError* oci_error_handler,
const char* query = 0)
std::cerr << fun << ": can't make " << oci_op << ": status = " << status;
if(status == OCI_SUCCESS_WITH_INFO ||
status == OCI_ERROR)
std::cerr << ", message = '";
text err_buf[1024] = "";
sb4 err_code = 0;
OCIErrorGet(
oci_error_handler,
(ub4)1,
0,
&err_code,
err_buf,
sizeof(err_buf),
(ub4)OCI_HTYPE_ERROR);
std::cerr << err_buf << "', error code = " << err_code;
exit(1);
if(query)
std::cerr << ", sql = " << query;
OCIHandlePtr<OCIEnv, OCI_HTYPE_ENV> environment_handle;
void connect(
OCIEnv* environment_handle,
const char* db,
const char* user,
const char* password,
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR>& error_handle,
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER>& server_handle,
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION>& session_handle,
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX>& svc_context_handle)
static const char* FUN = "connect()";
sword result;
// allocate an error handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &error_handle.fill(),
OCI_HTYPE_ERROR,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// allocate a server handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &server_handle.fill(),
OCI_HTYPE_SERVER,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
if((result = OCIServerAttach(
server_handle.get(),
error_handle.get(),
(text*)db,
strlen(db),
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIServerAttach", result, error_handle.get());
// allocate a service handle
if((result = OCIHandleAlloc(
environment_handle,
(void **) &svc_context_handle.fill(),
OCI_HTYPE_SVCCTX,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// set the server attribute in the service context handle
if((result = OCIAttrSet(
svc_context_handle.get(),
OCI_HTYPE_SVCCTX,
server_handle.get(),
sizeof(OCIServer*),
OCI_ATTR_SERVER,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// allocate a user session handle
if((result = OCIHandleAlloc(
environment_handle,
(void **)&session_handle.fill(),
OCI_HTYPE_SESSION,
0, // extra memory to allocate
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
// set username and password attributes in user session handle
if((result = OCIAttrSet(
session_handle.get(),
OCI_HTYPE_SESSION,
(text*)user,
strlen(user),
OCI_ATTR_USERNAME,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
if((result = OCIAttrSet(
session_handle.get(),
OCI_HTYPE_SESSION,
(text*)password,
strlen(password),
OCI_ATTR_PASSWORD,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
// start the session
if((result = OCISessionBegin(
svc_context_handle.get(),
error_handle.get(),
session_handle.get(),
OCI_CRED_RDBMS,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCISessionBegin", result, error_handle.get());
// set the user session attribute in the service context handle
if((result = OCIAttrSet(
svc_context_handle.get(),
OCI_HTYPE_SVCCTX,
session_handle.get(),
sizeof(OCISession*),
OCI_ATTR_SESSION,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
ub1 attr_value = 1;
if((result = OCIAttrSet(
server_handle.get(),
OCI_HTYPE_SERVER,
&attr_value,
sizeof(attr_value),
OCI_ATTR_NONBLOCKING_MODE,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrSet", result, error_handle.get());
void disconnect(
OCIEnv* environment_handle,
OCIError* error_handle,
OCIServer* server_handle,
OCISession* session_handle,
OCISvcCtx* svc_context_handle)
static const char* FUN = "disconnect()";
sword result;
if((result = OCISessionEnd(
svc_context_handle,
error_handle,
session_handle,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCISessionEnd", result, error_handle);
if((result = OCIServerDetach(
server_handle,
error_handle,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIServerDetach", result, error_handle);
OCILobLocator* FETCH_BUFFER_1[10000*1024];
char IND_BUFFER_1[10000*1024];
ub2 ERROR_BUFFER_1[1024];
OCIDefine* define_handle_1;
void clear_blob_buf(
OCILobLocator** buf,
unsigned long fetch_size)
for(unsigned long i = 0; i < 1024; ++i)
OCIDescriptorFree(
buf,
(ub4)OCI_DTYPE_LOB);
::memset(buf, 0, fetch_size * 1024);
uint32_t RET_LEN4;
sb4 oci_blob_callback(
dvoid* ctx,
OCIDefine* define,
ub4 iter,
dvoid** bufpp,
ub4** alenpp,
ub1* piecep,
dvoid** indpp,
ub2** rcodepp)
RET_LEN4 = sizeof(OCILobLocator*);
*bufpp = FETCH_BUFFER_1[iter];
*alenpp = &RET_LEN4;
*piecep = OCI_ONE_PIECE;
*indpp = IND_BUFFER_1 + iter;
*rcodepp = ERROR_BUFFER_1 + iter;
//std::cout << "iter: " << iter << std::endl;
return OCI_CONTINUE;
int define_column(
OCIEnv* environment_handle,
OCISvcCtx* svc_handle,
OCIStmt* stmt_handle,
OCIError* error_handle,
OCIDefine** define_handle,
unsigned long pos,
long oci_type,
unsigned long fetch_size,
OCILobLocator** buf,
char* ind_buf,
ub2* err_buf)
static const char* FUN = "define_column()";
sword result;
if(oci_type == SQLT_BLOB)
::memset(buf, 0, fetch_size * 1024);
for(int i = 0; i < 1024; ++i)
if((result = OCIDescriptorAlloc(
(dvoid*)environment_handle,
(dvoid**)&buf[i],
(ub4)OCI_DTYPE_LOB,
(size_t)0,
(dvoid**)0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDescriptorAlloc", result, error_handle);
ub2 size = 0;
OCIDescriptorPtr<OCIParam, OCI_DTYPE_PARAM> param_handle;
// ub2 oci_data_type = 0;
if((result = OCIParamGet(
stmt_handle,
OCI_HTYPE_STMT,
error_handle,
reinterpret_cast<void**>(¶m_handle.fill()),
pos)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIParamGet", result, error_handle);
if((result = OCIAttrGet(
param_handle.get(),
OCI_DTYPE_PARAM,
&size,
0,
OCI_ATTR_DATA_SIZE,
error_handle)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle);
if((result = OCIDefineByPos(
stmt_handle,
define_handle,
error_handle,
pos,
# ifdef _DYN
0,
-1,
#else
buf,
fetch_size,
#endif
oci_type,
ind_buf,
0,
err_buf, // ptr to array of column-level return codes
# ifdef _DYN
OCI_DYNAMIC_FETCH
# else
OCI_DEFAULT
# endif
)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
# ifdef _DYN
if((result = OCIDefineDynamic(
*define_handle,
error_handle,
0,
oci_blob_callback)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIDefineByPos", result, error_handle);
# endif
return 0;
int define_columns(
OCIEnv* environment_handle,
OCISvcCtx* svc_handle,
OCIStmt* stmt_handle,
OCIError* error_handle)
static const char* FUN = "define_columns()";
define_handle_1 = 0;
int pos = 1;
::memset(ERROR_BUFFER_1, 0, 1024 * sizeof(ERROR_BUFFER_1[0]));
define_column(
environment_handle,
svc_handle,
stmt_handle,
error_handle,
&define_handle_1,
pos++,
SQLT_BLOB,
sizeof(OCILobLocator*),
FETCH_BUFFER_1,
IND_BUFFER_1,
ERROR_BUFFER_1);
return 0;
int execute_select(
const char* db,
const char* user,
const char* password)
static const char* FUN = "execute_select()";
const unsigned long FETCH_COUNT = 1024;
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
connect(
environment_handle.get(),
db,
user,
password,
error_handle,
server_handle,
session_handle,
svc_context_handle);
OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
sword result;
if((result = OCIHandleAlloc(
environment_handle.get(),
(void**)&stmt_handle.fill(),
OCI_HTYPE_STMT,
0,
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
const char QUERY[] = "SELECT text FROM ADSERVERTEST_BLOB";
ub4 rows = 0;
if((result = OCIAttrSet(
stmt_handle.get(),
OCI_HTYPE_STMT,
(dvoid *)&rows,
(ub4)sizeof(ub4),
OCI_ATTR_PREFETCH_ROWS,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(
FUN, "OCIAttrSet(OCI_ATTR_PREFETCH_ROWS)", result, error_handle.get());
if((result = OCIStmtPrepare(
stmt_handle.get(),
error_handle.get(),
(text*)QUERY,
strlen(QUERY),
OCI_NTV_SYNTAX,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
ub2 stmt_type;
if((result = OCIAttrGet(
stmt_handle.get(),
OCI_HTYPE_STMT,
&stmt_type,
0,
OCI_ATTR_STMT_TYPE,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
ub4 prev_fetched = 0;
while((result = OCIStmtExecute(
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get(),
0,
0,
0,
0,
OCI_DEFAULT)) != OCI_SUCCESS)
if(result != OCI_STILL_EXECUTING)
throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
define_columns(
environment_handle.get(),
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get());
ub4 all_fetched_count = 0;
while(true)
while((result = OCIStmtFetch2(
stmt_handle.get(),
error_handle.get(),
FETCH_COUNT,
OCI_FETCH_NEXT,
1,
OCI_DEFAULT)) == OCI_STILL_EXECUTING
# ifdef _DYN
// || result == OCI_NEED_DATA
# endif
if (result != OCI_SUCCESS &&
result != OCI_NO_DATA &&
result != OCI_SUCCESS_WITH_INFO)
std::cerr << FUN << ": can't make OCIStmtFetch2: status = " << result;
std::cerr << ", message = '";
text err_buf[1024] = "";
sb4 err_code = 0;
OCIErrorGet(
error_handle.get(),
(ub4)1,
0,
&err_code,
err_buf,
sizeof(err_buf),
(ub4)OCI_HTYPE_ERROR);
std::cerr << err_buf << "', error code = " << err_code << ", row errors: ";
for(const ub2* cur = ERROR_BUFFER_1;
cur < ERROR_BUFFER_1 + 1024; ++cur)
if(*cur)
std::cerr << "#" << (cur - ERROR_BUFFER_1) << ": " <<
*cur << std::endl;
ub4 fetched_count = 0;
if((result = OCIAttrGet (
stmt_handle.get(),
OCI_HTYPE_STMT,
&fetched_count,
0,
OCI_ATTR_ROW_COUNT,
error_handle.get())) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIAttrGet", result, error_handle.get());
all_fetched_count += fetched_count;
if(fetched_count > 0)
for(unsigned long i = 0; i < fetched_count - 1; ++i)
ub4 lob_size;
while((result = OCILobGetLength(
svc_context_handle.get(),
error_handle.get(),
FETCH_BUFFER_1[i],
&lob_size)) == OCI_STILL_EXECUTING)
if(result != OCI_SUCCESS)
throw_oci_error(FUN, "OCILobGetLength", result, error_handle.get());
std::cout << "#" << i << ": ind = " << (unsigned long)IND_BUFFER_1[i] <<
", len = " << lob_size << std::endl;
if(fetched_count - prev_fetched < FETCH_COUNT)
break;
prev_fetched = fetched_count;
clear_blob_buf(
FETCH_BUFFER_1,
sizeof(OCILobLocator*));
while((result = OCIStmtFetch(
stmt_handle.get(),
error_handle.get(),
0,
OCI_FETCH_NEXT,
OCI_DEFAULT)) == OCI_STILL_EXECUTING
disconnect(
environment_handle.get(),
error_handle.get(),
server_handle.get(),
session_handle.get(),
svc_context_handle.get());
return 0;
int execute_update(
const char* db,
const char* user,
const char* password)
static const char* FUN = "execute_update()";
OCIHandlePtr<OCIError, OCI_HTYPE_ERROR> error_handle;
OCIHandlePtr<OCIServer, OCI_HTYPE_SERVER> server_handle;
OCIHandlePtr<OCISession, OCI_HTYPE_SESSION> session_handle;
OCIHandlePtr<OCISvcCtx, OCI_HTYPE_SVCCTX> svc_context_handle;
connect(
environment_handle.get(),
db,
user,
password,
error_handle,
server_handle,
session_handle,
svc_context_handle);
OCIHandlePtr<OCIStmt, OCI_HTYPE_STMT> stmt_handle;
for(int i = 0; i < 1000; ++i)
sword result;
if((result = OCIHandleAlloc(
environment_handle.get(),
(void**)&stmt_handle.fill(),
OCI_HTYPE_STMT,
0,
0)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIHandleAlloc", result, error_handle.get());
std::ostringstream sql;
std::string str;
std::string et("\xEB\xB2\x88");
unsigned long rep = ::rand() % 500 + 1;
str.reserve(rep*et.size());
for(unsigned long ei = 0; ei < rep; ++ei)
str.append(et);
sql << "BEGIN " <<
"UPDATE ADSERVERTEST_BLOB SET text = "
"utl_raw.cast_to_raw('" << str << "') "
"WHERE id = " << i <<
"END;";
if((result = OCIStmtPrepare(
stmt_handle.get(),
error_handle.get(),
(text*)sql.str().c_str(),
sql.str().length(),
OCI_NTV_SYNTAX,
OCI_DEFAULT)) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIStmtPrepare", result, error_handle.get());
while((result = OCIStmtExecute(
svc_context_handle.get(),
stmt_handle.get(),
error_handle.get(),
1,
0,
0,
0,
OCI_DEFAULT)) != OCI_SUCCESS)
if(result != OCI_STILL_EXECUTING)
throw_oci_error(FUN, "OCIStmtExecute", result, error_handle.get());
disconnect(
environment_handle.get(),
error_handle.get(),
server_handle.get(),
session_handle.get(),
svc_context_handle.get());
return 0;
void* select_thread(void* ctx)
while(true)
execute_select(
"//oraclept.ocslab.com/addbpt.ocslab.com",
"bs_unittest_4",
"adserver");
// std::cout << "select finished" << std::endl;
return ctx;
void* update_thread(void* ctx)
while(true)
execute_update(
"//oraclept.ocslab.com/addbpt.ocslab.com",
"bs_unittest_4",
"adserver");
// std::cout << "update finished" << std::endl;
return ctx;
int main()
static const char* FUN = "main()";
sword result;
// allocate an environment handle
if((result = OCIEnvCreate(
&environment_handle.fill(),
OCI_OBJECT | OCI_THREADED,
0, // context
0, // malloc
0, // realloc
0, // free
0, // extra memory to allocate
0) // pointer to user-memory
) != OCI_SUCCESS)
throw_oci_error(FUN, "OCIEnvCreate", result, 0);
pthread_t th1, th2;
pthread_create(&th1, 0, select_thread, 0);
pthread_create(&th2, 0, update_thread, 0);
pthread_join(th1, 0);
pthread_join(th2, 0);
return 0;
Edited by: user13011391 on 20.04.2010 5:50
Edited by: user13011391 on 20.04.2010 6:00
Edited by: user13011391 on 20.04.2010 6:15 -
Non-blocking Vectored read from SocketChannel fails
Hi.
Please look at the code example:
ByteBuffer tmp1 = ByteBuffer.allocate(500);
ByteBuffer tmp2 = ByteBuffer.allocate(500);
ByteBuffer[] tmp = {tmp1, tmp2};
while ((count = socketChannel.read(tmp)) > 0) {
+ "bytes.");
When I run this code, (using non-blocking socket channel), the first buffer is read ok, but on the second round of the while loop, I get an IOException, saying: "a non blocking socket operation could not be completed immediately".
If I put 'tmp1' instead of 'tmp' in the read(), (i.e - use a normal buffer), the read successfully finishes.
Why?
I found nothing in the documentation, and in the 'Java NIO' book (Ron Hitchens).
Help?
Thanks.Please ignore the + "bytes."); inside the while.
-
Non blocking worker servlet ?
Hi friends,
I have an issue to implement. We implemented a web application and now I want to separate some parts of this application. I can express the action shorter and simple below.
if a user requests x-y ticket {
���try {
������check db if x-y is available
������if true send available
������else not
���}catch (NonExistentData) {
������addJob2Queue(x-y)
������send available
���}
class AvailabilityHelper extends Thread{
���run(){
������while(true){
���������checkQueue
���������if there is job, updateDBfor(org,dest)
������}
���}
* updateDBfor(org,dest) includes other ejb references to request data and insert it into db
This web aplication runs with JSP 1.2 EL support on WAS 5.1
the check for db and the thread implementation was in a seperate package and were used in actions of web application. Now they also want to use these checks for other (non web) applications. So i think there should be a session bean in ejb and should process these requests and I used JMS (Message-Driven Bean) with WebSphere MQ to undertake the thread and queue mechanism.
Now it works like this :
class exampleSessionBean{
���getAvalibability(org, dest){
������try {
���������check db if x-y is available
���������if true send available
���������else not
������}catch (NonExistentData) {
���������queueSender.sendMessage(update x-y)
���������send available;
������}
���}
class queueMDB{
���onMessage(){
������updateDBfor(org,dest)
���}
The purpose of this applications was, not to block the user for db update process, if there is data in db select and show to the user. the update process of db includes other ejb references and takes so much time. It is nonsense to make the user wait such time. And the info is not a big deal, because of this when i put a request for update, without blocking i send it as available...
So what is the problem ? :) Deployment team don't want to pay for websphere MQ and hire a admin for that. Also they don't want to use Embedded Messaging server client (JMS Server) of WAS. So I am asking you: is there a way to implement a non blocking servlet so that i will just make a request and don't wait for response, or a servlet will take the request and release the connection but will continue to process the request ?
thanks for all...I tried to implement a web application and add a ServletContextListener as stevejluke suggests. But on contextInitialized function when creating new JobConsumer it gets following errors on server.
6/27/06 12:51:36:391 CEST] 33238138 WebContainer A SRVE0169I: Loading Web Module: non-blocking.
[6/27/06 12:51:36:438 CEST] 33238138 SystemOut O OlaListener initializing...
[6/27/06 12:51:36:516 CEST] 33238138 SystemOut O OlaListener - Queue added
[6/27/06 12:51:36:516 CEST] 33238138 SystemOut O OlaListener - keepWorking
[6/27/06 12:51:36:672 CEST] 33238138 WebApp E SRVE0015E: Failure to initialize Web application non-blocking
[6/27/06 12:51:36:844 CEST] 33238138 WebGroup E SRVE0054E: An error occurred while loading Web application
public class OlaListener implements ServletContextListener {
* @see javax.servlet.ServletContextListener#void (javax.servlet.ServletContextEvent)
public void contextDestroyed(ServletContextEvent event) {
ServletContext context = event.getServletContext();
context.setAttribute("keepWorking", Boolean.FALSE);
* @see javax.servlet.ServletContextListener#void (javax.servlet.ServletContextEvent)
public void contextInitialized(ServletContextEvent event) {
System.out.println("OlaListener initializing...");
ServletContext context = event.getServletContext();
WorkQueue newJobs = new WorkQueue();
context.setAttribute("newJobs", newJobs);
System.out.println("OlaListener - Queue added");
context.setAttribute("keepWorking", Boolean.TRUE);
System.out.println("OlaListener - keepWorking");
JobConsumer jc = new JobConsumer();
System.out.println("OlaListener - Job Consumer created");
jc.setContext(context);
System.out.println("OlaListener - context set");
Thread t = new Thread(jc);
t.start();
public class JobConsumer implements Runnable{
/*log4j*/ private static final Logger logger = Logger.getLogger(JobConsumer.class);
private ServletContext context = null;
public void run(){
System.out.println("JobConsumer - run Start");
processQueue(context);
System.out.println("JobConsumer - run End");
}
Maybe you are looking for
-
Firefox 3.6.8 will not start. I have to go to safe start, click reset to default, ok, then the shutdown box appears, I click cancel and it will open. I have rest profile, uninstalled and reinstalled, clicked alll he boxes on safe start, tried an olde
-
How do i copy pictures from my pc to my ipad
How do I copy pictures from my pc to my ipad
-
"Text Table must be converted" error
BW Gurus, We just applied stack 15 to our BI 7.0 system (SAP_BW 0017), and are now getting an error with one of our infoobjects. The error states that the text table must be converted, as below, but we're not quite sure what this means. This infoobj
-
Solved flicker problem with newer fglrx drivers
This has been annoying me since the move from 8.29 to 8.30: I have an integrated Xpress 200 on my laptop, and newer proprietary drivers caused the screen to flicker. This has caused me to stick with the older drivers, which restricted upgrades to X.o
-
SharePoint 2010: How to map documentset attibutes to objects - In SharePoint Webpart
Hey, I guess it's a pretty simple question but I really do not get one inch closer to a solution. I'm working on a WebPart on SharePoint 2010 which manages a documentset (document library with an custom content type). Creating an storing of documents