~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/jinterface/java_src/com/ericsson/otp/erlang/OtpMbox.java

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
   * @return an {@link OtpErlangObject OtpErlangObject} representing
144
144
   * the body of the next message waiting in this mailbox.
145
145
   *
 
146
   * @exception OtpErlangDecodeException if the message can not be
 
147
   * decoded.
 
148
   *
146
149
   * @exception OtpErlangExit if a linked {@link OtpErlangPid pid} has
147
150
   * exited or has sent an exit signal to this mailbox.
148
 
   *
149
151
   **/
150
152
  public OtpErlangObject receive() 
151
 
    throws OtpErlangExit {
 
153
    throws OtpErlangExit, OtpErlangDecodeException {
152
154
    try {
153
155
      return receiveMsg().getMsg();
154
156
    }
155
157
    catch (OtpErlangExit e) {
156
158
      throw e;
157
159
    }
158
 
    catch (Exception f) { }
159
 
    return null;
 
160
    catch (OtpErlangDecodeException f) {
 
161
      throw f;
 
162
    }
160
163
  }
161
164
  
162
165
  /**
168
171
   * @return an {@link OtpErlangObject OtpErlangObject} representing
169
172
   * the body of the next message waiting in this mailbox.
170
173
   *
 
174
   * @exception OtpErlangDecodeException if the message can not be
 
175
   * decoded.
 
176
   *
171
177
   * @exception OtpErlangExit if a linked {@link OtpErlangPid pid} has
172
178
   * exited or has sent an exit signal to this mailbox.
173
 
   *
174
179
   **/
175
180
  public OtpErlangObject receive(long timeout) 
176
 
    throws OtpErlangExit {
 
181
    throws OtpErlangExit, OtpErlangDecodeException {
177
182
    try {
178
183
      OtpMsg m = receiveMsg(timeout);
179
184
      if (m != null) return m.getMsg();
181
186
    catch (OtpErlangExit e) {
182
187
      throw e;
183
188
    }
184
 
    catch (Exception f) { }
 
189
    catch (OtpErlangDecodeException f) {
 
190
      throw f;
 
191
    }
 
192
    catch (InterruptedException g) { }
185
193
    return null;
186
194
  }
187
195
 
244
252
    case OtpMsg.exit2Tag:
245
253
      try {
246
254
        OtpErlangObject o = m.getMsg();
247
 
        throw new OtpErlangExit(o.toString(),m.getSenderPid());
 
255
        throw new OtpErlangExit(o,m.getSenderPid());
248
256
      }
249
257
      catch (OtpErlangDecodeException e) {
250
258
        throw new OtpErlangExit("unknown",m.getSenderPid());
281
289
    case OtpMsg.exit2Tag:
282
290
      try {
283
291
        OtpErlangObject o = m.getMsg();
284
 
        throw new OtpErlangExit(o.toString(),m.getSenderPid());
 
292
        throw new OtpErlangExit(o,m.getSenderPid());
285
293
      }
286
294
      catch (OtpErlangDecodeException e) {
287
295
        throw new OtpErlangExit("unknown",m.getSenderPid());
343
351
   **/
344
352
  public void send(String name, String node, OtpErlangObject msg) {
345
353
    try {
346
 
      if (node.equals(home.node())) {
347
 
        send(name,msg);
348
 
      }
 
354
      String currentNode = home.node();
 
355
      if (node.equals(currentNode))
 
356
        send(name,msg);
 
357
      else if (node.indexOf('@',0)<0 && 
 
358
               node.equals(currentNode.substring(0,currentNode.indexOf('@',0))))
 
359
        send(name,msg);
 
360
 
349
361
      else {
 
362
        // other node
350
363
        OtpCookedConnection conn = home.getConnection(node);
351
364
        if (conn == null) return;
352
365
        conn.send(self,name,msg);
356
369
  }
357
370
 
358
371
  /**
 
372
   * Close this mailbox with the given reason.
 
373
   *
 
374
   * <p> After this operation, the mailbox will no longer be able to
 
375
   * receive messages. Any delivered but as yet unretrieved messages
 
376
   * can still be retrieved however. </p>
 
377
   *
 
378
   * <p> If there are links from this mailbox to other {@link
 
379
   * OtpErlangPid pids}, they will be broken when this method is
 
380
   * called and exit signals will be sent. </p>
 
381
   *
 
382
   * @param reason an Erlang term describing the reason for the exit.
 
383
   **/
 
384
  public void exit(OtpErlangObject reason) {
 
385
    home.closeMbox(this, reason);
 
386
  }
 
387
 
 
388
  /**
 
389
   * Equivalent to <code>exit(new OtpErlangAtom(reason))</code>. </p>
 
390
   *
 
391
   * @see #exit(OtpErlangObject)
 
392
   **/
 
393
  public void exit(String reason) {
 
394
    exit(new OtpErlangAtom(reason));
 
395
  }
 
396
 
 
397
  /**
359
398
   * <p> Send an exit signal to a remote {@link OtpErlangPid pid}.
360
399
   * This method does not cause any links to be broken, except
361
400
   * indirectly if the remote {@link OtpErlangPid pid} exits as a
364
403
   * @param to the {@link OtpErlangPid pid} to which the exit signal
365
404
   * should be sent.
366
405
   *
367
 
   * @param reason a string indicating the reason for the exit.
 
406
   * @param reason an Erlang term indicating the reason for the exit.
368
407
   **/
369
408
  // it's called exit, but it sends exit2 
 
409
  public void exit(OtpErlangPid to, OtpErlangObject reason) {
 
410
    exit(2,to,reason);
 
411
  }
 
412
 
 
413
  /**
 
414
   * <p> Equivalent to <code>exit(to, new
 
415
   * OtpErlangAtom(reason))</code>. </p>
 
416
   *
 
417
   * @see #exit(OtpErlangPid, OtpErlangObject)
 
418
   **/
370
419
  public void exit(OtpErlangPid to, String reason) {
371
 
    exit(2,to,reason);
 
420
    exit(to, new OtpErlangAtom(reason));
372
421
  }
373
422
 
374
423
  // this function used internally when "process" dies
375
424
  // since Erlang discerns between exit and exit/2.
376
 
  private void exit(int arity, OtpErlangPid to, String reason) {
 
425
  private void exit(int arity, OtpErlangPid to, OtpErlangObject reason) {
377
426
    try {
378
427
      String node = to.node();
379
428
      if (node.equals(home.node())) {
530
579
   *
531
580
   * <p> If there are links from this mailbox to other {@link
532
581
   * OtpErlangPid pids}, they will be broken when this method is
533
 
   * called and exit signals will be sent. </p>
 
582
   * called and exit signals with reason 'normal' will be sent. </p>
534
583
   *
 
584
   * <p> This is equivalent to {@link #exit(String)
 
585
   * exit("normal")}. </p>
535
586
   **/
536
587
  public void close() {
537
588
    home.closeMbox(this);
586
637
  }
587
638
 
588
639
  // used to break all known links to this mbox
589
 
  void breakLinks(String reason) {
 
640
  void breakLinks(OtpErlangObject reason) {
590
641
    Link[] l = links.clearLinks();
591
642
 
592
643
    if (l != null) {