[NIO] custom messages from the netwerk

Hi you all,
Yes this is another NIO question :)
Ok I have the following situation, I've got a NIO server which reads custom messages from the netwerk. These messages consists of an interger and then a variable byte array.
int -> length of the message
byte array -> data of message (could be anything)
On my local network it works fine because I don't have to worry about my read() not reading all the bytes the client send. So I can just use the ByteBuffer.getInt() to read the int and create a buffer for the byte array etc.
But... on the intenet there is no garentee all the bytes are read. So if only the first 3 bytes of the whole message are in my read buffer and I call the getInt() I'll get an exception.
How would you fix this? The only garentee is that I will always have 1 byte (except when a connection is closed or other error)
I could create of small bytebuffer of 4 bytes and wait till it's full and then read the int, but what if I also have a length that can consist out of like 5 or 6 bytes... and I don't know by forehand if it's 4 or 5 or 6... or just 2...
Any idear would be welcome... or even code if you have the time...
Grtz
David

Use ByteBuffer[] { lengthField, dataField } as a structure for messages. Set the size of the length field statically as part of the protocol. Set dataField's limit to 0. Do readsinto this structure (there is an appropriate read method for an array of ByteBuffers) until there lengthField.remaining() == 0. At this point, read the int/long/whatever from lengthField and set dataField's limit to that. Then do the reads necessary until dataField.remaining() == 0. At this point, you'll have your whole message.
The reason that I say "do reads" is that on any particular read you may only get one byte's worth of data. Therefore you have to hold this partially completed message in some variable, or as an attachment to the SelectionKey which was selected. As the Channel continually gets selected for OP_READ, you can do the above steps, and if there's not enough left in the channel, you just leave the message partially completed for the next OP_READ. Once it's complete, you do what you need to with it, and replace the attachment or variable with an empty ByteBuffer[] of the above format.
--Dan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How can i get the error message from the thrown/raised exception?

    DB version:10gR2
    Examples for this thread taken from
    Want Stored Procs to get exectuted regardless of preceeding SPs Success or
    I have a package with several functions and procedures inside.I created a caller procedure called callProcs, which will execute various procedures within the package in the appropriate order.
    In the below example i cannot get the error message thrown from line 20
    create or replace package body mypackage
    is
    variable_proc1 number;
    variable_proc2 number;
    variable_proc3 number;
    v_result       number;
    my_exception   exception;
    procedure proc1
    is
    begin
    select 8/0 into variable_proc1 from dual;
    exception
              when others
              then raise my_exception; ----line 20
    end;
    procedure proc2
    is
    begin
    select 1 into variable_proc2 from dual;
    exception
              when others
              then
                   null;
    end;
    procedure proc3
    is
    begin
    select 3 into variable_proc3 from dual;
    exception
              when others
              then
                   null;
    end;
    Procedure caller_proc
    is
    begin
    proc1;
    proc2;
    proc3;
    v_result:=variable_proc2+variable_proc3;
    dbms_output.put_line('The output is '||v_result);
    exception
              when my_exception
              then
    dbms_output.put_line('Heyyyyy the error is '||SQLERRM); -- exception caught at line 64 of caller proc
    end;
    end mypackage;
    When i try executing the caller proc, i don't get the error. Instead i get the text User-Defined Exception as shown below
    set serveroutput on
    exec mypackage.caller_proc;
    Heyyyyy the error is User-Defined Exception
    PL/SQL procedure successfully completed.Edited by: user10633418 on Mar 10, 2009 11:30 PM

    Thank you justin.
    Sorry my earlier post was a bit ambiguous.
    I wanted the error generated at proc1 to be captured at caller proc's Exception handling section (line 64) so that i could log the error to an ERR_LOG table.
    I can actually log this error at proc1 itself like
    exception
    when others
    THEN
    error_message :='My custom message for the particular proc '||SQLERRM;
    dbms_output.put_line(error_message);
    logerror(error_message); --an autonomous error logging proc
    raise;But there is a RAISE statement in proc1's exception handling, so the exception gets propogated to caller proc's exception handling section {color:#ff0000}*and another redundant row will be created at ERR_LOG table for the same error because there is a*{color}
    logerror(error_message);--an autonomous error logging proc
    in the WHEN OTHERS section of exception handling section of the caller proc
    I want to avoid the creation of this redundant row in ERR_LOG table.

  • Message from the NSAPI plugin: "Internal Server Failure"

    Can someone explain the possible causes of the following message displayed when rendering a page:
    Message from the NSAPI plugin:
    Internal Server failure, NSAPI plugin. Cannot continue.
    Build date/time: Nov 10 2005 15:25:36
    Change Number: 673701
    Thanks

    you are probably using a custom NSAPI plugin from a 3rd party company that is emitting this message. to get more information on this issue, you can look into the NSAPI plugins loaded by <https-hostname>/config/magnus.conf and find out which nsapi plugin is causing this error. nsapi plugins bundled within web server like j2eeplugin or fastcgi does not emit this error
    also, you can increase the server log verbosity (by setting <log-level>finest</log-level> in config/server.xml and restarting the server
    hth

  • How Can I delete multiple messages from the same address in Mac Mail

    Hope this is in the correct Community.  Hope someone can help me to delete multiple email messages from the same email address.
    At the moment I can do it by holding down the Command key and highlighting each email, but that can be difficult with many messages
    to delete.  Is there a quicker way?
    Thanks for any help on this.

    Thanks for the reply, appreciate your input.  I did find another way of doing it and that is to highlight the first e-mail, hold down the shift key and click on the last one.  That highlights them all and then they can all be deleted.  Your ideas also work of course and I thank you for that.  Cheers.

  • How to delete message from the fodler of  AOL account using Java mail

    Hello All,
    I am using Java MAil API in my application, i want to delete message from AOL account's folder,
    when i set the folder as "Recently Deleted" or "Trash" , i get an exception as "folder does not exist".
    when i tested , some times mail is moving into Recently Deleted folder, but not every time.
    this is happening in both the interface as AOl Interface or my application.
    when i use folder.close(true) after setting the flag of message as DELETED. it completely remove the message from the acount.
    but i want to let the message be remained in the Recently Deleted folder. what should i do.
    i dont want to remove the message completely from the account.I am using IMAP also.

    You'll need to figure out what the real name of the "Recently Deleted" folder is on the AOL IMAP server
    (assuming it's a real folder and not some sort of "virtual" folder), then copy the message into that folder.
    See the folderlist.java demo program as a way to explore the names of all the folders on the server.

  • How can I get rec'd text messages from the same subscriber not be appended

    Hi,
    Is there a way to configure the Apple iphone so that text messages from the same subscriber are displayed separately rather than appended to each other? In this way accidentally deleting one message wouldn't delete the entire history of messages from this subscriber.
    When I launch the SMS service by pressing the green SMS button I am met by a screen that says Text Messages. On the left of this there is a button that says Edit and on the right there is one that is for writing a new message. Down the page are my messages all grouped by the originator of each messages. If I choose one I see that all messages from this source are present appended one after the other. There is also the option now to Clear on the top right hand corner. It is this Clear option I am worried about. If I choose Clear I am asked for a confirmation and then lo and behold as expected all my messages from this subscriber are deleted.
    This is a work phone for support purposes and most of the texts will be from the telephone operator (i.e. the one same number) saying we have an email waiting to be read with a subject title giving a little description. I want to be in a position so that I don't accidentally delete the entire history of messages, say some evening when I'm tired or Monday morning if I 'm a bit asleep. Ideally I would prefer that each text message would stand alone in the Text Messages window irrespective of the originator and not be appended in a group fashion. Is there a way to do this?
    Kind regards,
    M

    There is no way to do that on the iPhone. Messages will always be grouped into a 'conversation' based on the sender/recipient. Only Apple can change that behavior.
    You can submit feedback to Apple: http://www.apple.com/feedback/iphone.html.

  • A message from the creator of Skype?

    Hello,
    a freind of mine got this kessage and I wanted to know if it is official. (I am guessing no, but better safe than sorry).
    <<<  Hi , this is a message from the creator of Skype and it tells you a little bit about what is going to happen to Skype on the 15th of March. Please don't send this back to the person you recieved it from. Dear Skype members, Skype is supposed to be closing down March 15th because it is becoming very overpopulated. There have been many members complaining that Skype is becoming very slow. Records show that there are many active Skype members and also many new members. We will be sending this message around to see if members are active or not. If you are active please send to 15 other users using copy+paste to show that you are still active. *Those who do not send this message within 2 weeks
     will be deleted without hesitation to make more space. Send this message to all of your friends to show that you are still active and you will not be deleted. Founder of Skype...remember to send this to 15 other people so your account SEND THIS MESSAGE TO 15 FRIENDS TO KEEP YOUR SKYPE ACCOUNT—
    Thank you. Peace Out.

    Hi!
    First of all, would the creator of Skype acually want you to send this message to 15 people? How the heck would he know!!!
    1. He wouldn't know how many people it was sent to, you could've sent it to only 1!!
    2. He wouldn't know the people the message was sent to.
    3. Would he know if you EVEN GOT THE MESSAGE IN THE FIRST PLACE?!?!?
    This is actually a scam circulating all over IMs connected to the internet. This is just a chain letter. Look at all the typos in this. So, the next time you see 'Send this to 15 people or else', DELETE.
    Br,
    BlackIncerator

  • Error message from the source system, Caller 09 contains an error message.

    Hi,
        Guru's, i got an error massage when my process chain is running(Daily) in BIW 7.0, the error got in Data Loading from source to PSA or data targets. The errors having the below details
    Error message from the source system
    Diagnosis
    An error occurred in the source system.
    System Response
    Caller 09 contains an error message.
    Further analysis:
    The error occurred in Extractor .
    Refer to the error message.
    Procedure
    How you remove the error depends on the error message.
    Note
    If the source system is a Client Workstation, then it is possible that the file that you wanted to load was being edited at the time of the data request. Make sure that the file is in the specified directory, that it is not being processed at the moment, and restart the request.   "
    Can any body help me out of this situation what to do and how to resolv ethe problem.
    Thanks and Regards,.
    Taps....

    Caller 09 is a very common issue - please search the forums before posting....
    Arun

  • Ever since I enabled iMessage on my Mac Airbook, I can no longer receive text messages from the iMessage people on my iPhone, only on my iMessage now!!  How do I get the messages to reach both iMessage and iPhone??

    Ever since I enabled iMessage on my Mac Airbook, I can no longer receive text messages from the iMessage people on my iPhone, only on my iMessage now!!  How do I get the messages to reach both iMessage and iPhone??

    We are suffering very similar issues when communicating from my iphone to a friend who has both iphone and iPad enabled.
    As long as I reply to an existing text chain, then it is visible on the target iphone.  If I SMS the phone number, it gets routed to the IPAD!!   And NO, I should not have to disable imessage when I want to send an SMS!!

  • Java - Axis2: How to get an error code / error message from the Javascript via SOAP

    Hi
    In our Java applicsation we call a Javascript in a Indesign CS Server using the following code:
    --- SNIP BEGIN ---
    // calls the remote service on the indesign server
    try {
    // create service
    ServiceStub oIndsgnSrvStub = new
    ServiceStub(sIndesignServer);
    // create service parameter
    ServiceStub.RunScriptParameters
    oIndsgnSrvRSParams = new ServiceStub.RunScriptParameters();
    // create arguments with source- and target-file for parameter
    ServiceStub.IDSPScriptArg[] oIndsgnSrvSArgs = new ServiceStub.IDSPScriptArg[2];
    oIndsgnSrvSArgs[0] = new
    ServiceStub.IDSPScriptArg();
    oIndsgnSrvSArgs[0].setName("xml-input");
    oIndsgnSrvSArgs[0].setValue(sSourceFile);
    oIndsgnSrvSArgs[1] = new
    ServiceStub.IDSPScriptArg();
    oIndsgnSrvSArgs[1].setName("output-file");
    oIndsgnSrvSArgs[1].setValue(sTargetFile);
    // define service parameter
    oIndsgnSrvRSParams.setScriptArgs(oIndsgnSrvSArgs);
    oIndsgnSrvRSParams.setScriptFile(sScriptFile);
    oIndsgnSrvRSParams.setScriptLanguage("javascript");
    oIndsgnSrvRSParams.setScriptText("");
    // create runscript
    ServiceStub.RunScript oIndsgnSrvRS = new ServiceStub.RunScript();
    // set parameter
    oIndsgnSrvRS.setRunScriptParameters(oIndsgnSrvRSParams);
    //$$$ there should be an answer returned by the InddSrvr
    // execute SOAP call
    ServiceStub.RunScriptResult oIndsgnSrvRes = oIndsgnSrvStub.RunScript(oIndsgnSrvRS);
    if(oIndsgnSrvRes.getErrorNumber() == 0) {
    oServerProdJob.setProdState(CBP_Constant.REMOTEPRODUCTIONSTATE_SUCCESS);
    bOK = true;
    } else {
    oServerProdJob.setProdState(CBP_Constant.REMOTEPRODUCTIONSTATE_FAILURE);
    bOK = false;
    //$$$ should be set, if there is something returned by inddsrvr
    //oServerProdJob.setErrorMsg(sErrorMsg);
    } catch(Exception e) {
    sError += e.getMessage() + "\n";
    bOK = false;
    --- SNIP END -----
    The problem is that we don't get the error code and/or the error message from the Javascript in oIndsgnSrvRes. The error code is always 0 if I set an Integer value as return in the Javascript. If I set a String, there is an Exception in the Java application.
    Here is the Java script we use:
    --- SNIP BEGIN ---
    main();
    main()
    var sError = "";
    var sXMLInput = "";
    var sLayoutPath = "";
    // get the SDKCodeSnippetRunner object
    var cbpAdapter = app.cbpCbpadapterObject
    if (cbpAdapter) {
    sXMLInput=app.scriptArgs.get("xml-input");
    sLayoutOutputFile=app.scriptArgs.get("output-file");
    sError = cbpAdapter.doProcess(sXMLInput, sLayoutOutputFile);
    return sError; // This give an Exception; if I return an Integer the ScriptResult is always 0
    --- SNIP END -----
    If I try this with the test application from Adobe I get the error code correctly. But in the Java application, using SOAP, I can't get the error code.
    What could be wrong?
    Any ideas?
    Thanks a lot for the support.
    Kind regards
    Hans

    user11340104 wrote:
    Hello -
    i am calling sqlplus from a bash shell script. If the sql statement generates an error, how can I return that error code (unsuccessful) back to the bash shell?
    Well, let google be your friend,
    http://www.google.co.in/search?rlz=1C1GGLS_enIN327IN327&sourceid=chrome&ie=UTF-8&q=sqlplus+error+codes
    There are many threads I guess talking about the same issue.
    HTH
    Aman....

  • Message from the IP_IN_QUEUE is automatically dequed

    Hi all,
    There are 2 messages in the IP_IN_QUEUE. I tried to dequeue it from BPEL using the AQ Adapter, but it is not dequeing. One of the reason could be the Payload structure of the existing messages in the IP_IN_QUEUE is different from the Payload structure of the schema imported in the BPEL Designer.
    So I thought of Enqueue a new message into the IP_IN_QUEUE and then thought of dequeue with the same message structure from BPEL thru AQ Adapter.
    I am able to enqueue a new message. I can able to see a new record inserted into the table IP_QTAB for the queue IP_IN_QUEUE, corresponding to this new enqueue message. But after some times, this message is automatically dequeued from IP_IN_QUEUE(i.e the corresponding row is automatically removed IP_QTAB)
    Can any one tell me how the message can be automatically dequeued from IP_IN_QUEUE. Also suggest if there are any way to find what are all the messages dequeued from IP_IN_QUEUE and what process dequeues them.
    Any help is highly appreciated.

    Hi,
    There are no automatic processes that dequeue messages from the IP_IN_QUEUE. When you dequeue a message from the IP_IN_QUEUE, you must make sure that the consumer name matches. The default consumer name is b2buser when B2B Server enqueues to the IP_IN_QUEUE. However, the default can be overrided by the Document Routing ID in the Document Definition Parameters page. If you are enqueuing from BPEL, you may have selected something totally different. I do not know of ways to track how the message is dequeued. You may want to post that question to the Oracle AQ forum.
    One suggestion is setup the tutorial so that you have the end to end scenario working. You can use the deq.bat or deq.sh in the $ORACLE_HOME/ip/tutorial/X12/runtime directory (for example, if you use the X12 tutorial) to dequeue messages from IP_IN_QUEUE. The default consumer name b2buser is assumed. After you are able to do that, then you want to try dequeueing using BPEL.
    Eng

  • MQ Adapter does not clear the rejected message from the queue

    Hi All,
    I'm using a MQ Adapter to fetch the message from the queue without any Backout queue configured. However, whenever there is any bad structured message found in the queue, MQ adapter rejects the message and moves the message to the rejmsg folder but does not clear it off the queue, as a result of which it keeps retrying the same hence, filling the logs and the physical memory. Somehow we do not have any backout queue configured so I can move the message to blackout queue. I have tried configuring the jca retry properties and global jca retry as well but to no avail.
    - Is it not the default behaviour of MQ Adapter to remove the rejected message from the queue irrespective of Backout queue is configured or not? The same behaviour working well with the JMS and File Adapter though.
    - Is there any way I can make MQ Adapter delete the message from that queue once it is rejected?
    Regards,
    Neeraj Sehgal

    Hi Jayson,
    Check this URL which answers a problem with com.sap.engine.boot.loader.ResourceMultiParentClassLoader problem:
    http://209.85.175.132/search?q=cache:RnFZ9viwuKkJ:https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.sdn.folder.sdn!2fcom.sap.sdn.folder.application!2fcom.sap.sdn.folder.roles!2fcom.sap.sdn.folder.navigationroles!2fcom.sap.sdn.role.anonymous!2fcom.sap.sdn.tln.workset.forums!2fforumtest!2fcom.sap.sdn.app.iview.forumthread%3FQuickLink%3Dthread%26tstart%3D45%26threadID%3D1020700+com.sap.engine.boot.loader.ResourceMultiParentClassLoader&hl=en&ct=clnk&cd=3&gl=in&client=firefox-a
    Please check that the JDK compliance level is at 5.0
    Window->Preferences->Java->Compiler->Compiler compliance level set this to 5.0
    Set the installed JRE to the one you have mentioned JDK 5.0 update 16
    Window->Preferences->Java->Installed JRE's->
    Click on the add button to select the path of your JDK.
    once completed click on the check box next to it.
    regards,
    AKD

  • Need  to read messages from the log instead of displaying

    Hi,
    I need to read all the messages from the log with a particular log no..
    i was able to display it using FM  BAL_DSP_LOG_DISPLAY..But i want to collect the messages instead of displaying..To display according to my requirement..
    Thanks in advance

    Use this for reading :
    BAL_LOG_MSG_READ
    Regards
    Neha

  • HT1277 How do I make Mail remove junk/deleted messages from the server? The only option tht works for me now is the "Remove from server" button at Account Info Messages on server.

    How do I make Mail remove junk/deleted messages from the server? The only option tht works for me now is the "Remove from server" button at Account Info > Messages on server. What am I doing wrong?

    Mail > Preferences… > Accounts > Advanced > Remove copy from server after retrieving a message

  • Database Connection Error: Cannot obtain error message from the server

    I have a SQL statement that wants to add a temp table to the database.   The SQL statement works fine but when I try to add it via 'Add Command' feature in Crystal XI R2, I get the following error message:
    Database Connection Error: Cannot obtain error message from the server
    Any ideas?
    Thanks in advance,
    Zack H.

    Hi Raghavendra,
    I am using this in the 'Add Command' feature but I get the error message displayed in the subject line:
    CREATE TABLE #TibetanYaks(
    YakID char(4),
    YakName char(20) )
    INSERT INTO #TibetanYaks (YakID, YakName)
    SELECT  LastName, FirstName
    FROM      Employee
    WHERE      EmployeeID between '2000' and '3000'
    I haven't tried to add this as a stored procedure but I imagine it will work as I have no problems yet with stored procedures.  I simply want to be able to use temporary tables for the sole purpose of that session and not creating anything static in the database.
    By the way, even though I get the error message, when I look on the backend database, I see that the temporary table was successfully created...its just not brought across correctly in Crystal.
    Any ideas?
    Zack H.

Maybe you are looking for

  • Can not connect outside of Lan to with rtsp PVC2300

    I have the following cameras set up at my office 1 - PVC2300 2 - WVC54GC 3 - AXIS 225FD I have a BEFSR81 Router I have a computer on Windows XP running the surv software to record.  Everything with that is good. I also have 2 desktops. I have been pl

  • Windows 7 64 bit driver for the Zen Vision M?

    - Where EXACTLY can I find the Windows 7 64-bit driver for the Zen Vision M? My new computer came with it installed in Windows Media Player 2, but the driver became corrupt. I can't seem to find that driver on the Creative or Microsoft download websi

  • 0FI_AR_4 Delta Timestamp

    Hello, We are using 0FI_AR_4 to extract our AR line items. There seems to be a time delay of 1 DAY for us to get new/changed records. We are on SAP_APPL 603 level 0004. I went through the forum and also looked at SAP Note : 991429. This seems to be f

  • FEBA, FB05 and F-44....

    Hello FI Gurus, I am working on Segregartion of duties. I wanted to clear some doubts I have. What is the use of transaction FEBA, FB05 and F-44 ? Are they interlinked ? Does FEBA requires FB05 to work in background ? Regards, Rajesh.

  • I am trying to get the verification code to be able to send photo emails and i don't seem to be able to get the CODE.

    I need help getting my photo email set up. I keep getting a message to type in the verification code that was sent to me in an email.. I have three emails but no code number.  Can someone help me with this