• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iluwatar / java-design-patterns / #1672

06 Sep 2015 05:33PM UTC coverage: 85.286% (-0.4%) from 85.644%
#1672

push

Markus
Removed the Markdown Plus custom heading id's

Because the renderer of github doesnt support markdown plus...

3246 of 3806 relevant lines covered (85.29%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.73
/poison-pill/src/main/java/com/iluwatar/poison/pill/Producer.java
1
package com.iluwatar.poison.pill;
2

3
import java.util.Date;
4

5
import com.iluwatar.poison.pill.Message.Headers;
6

7
/**
8
 * Class responsible for producing unit of work that can be expressed as message and submitted to queue
9
 */
10
public class Producer {
11

12
        private final MQPublishPoint queue;
13
        private final String name;
14
        private boolean isStopped;
15

16
        public Producer(String name, MQPublishPoint queue) {
1✔
17
                this.name = name;
1✔
18
                this.queue = queue;
1✔
19
                this.isStopped = false;
1✔
20
        }
1✔
21

22
        public void send(String body) {
23
                if (isStopped) {
×
24
                        throw new IllegalStateException(String.format("Producer %s was stopped and fail to deliver requested message [%s].", body, name));
×
25
                }
26
                Message msg = new SimpleMessage();
×
27
                msg.addHeader(Headers.DATE, new Date().toString());
×
28
                msg.addHeader(Headers.SENDER, name);
×
29
                msg.setBody(body);
×
30

31
                try {
32
                        queue.put(msg);
×
33
                } catch (InterruptedException e) {
×
34
                        // allow thread to exit
35
                        System.err.println(e);
×
36
                }
×
37
        }
×
38

39
        public void stop() {
40
                isStopped = true;
×
41
                try {
42
                        queue.put(Message.POISON_PILL);
×
43
                } catch (InterruptedException e) {
×
44
                        // allow thread to exit
45
                        System.err.println(e);
×
46
                }
×
47
        }
×
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc