blob: 803f3a6f11d4d085fcec0d45546ffc7a9147ed6a [file] [log] [blame]
Pierre De Rop40618d62010-02-18 21:01:20 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.apache.felix.dm.test.bundle.annotation.temporal;
20
21import org.apache.felix.dm.annotation.api.Service;
Pierre De Rop40618d62010-02-18 21:01:20 +000022import org.apache.felix.dm.annotation.api.Start;
23import org.apache.felix.dm.annotation.api.Stop;
Pierre De Rop624fec82010-05-10 21:48:38 +000024import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
25import org.apache.felix.dm.annotation.api.dependency.TemporalServiceDependency;
Pierre De Rop40618d62010-02-18 21:01:20 +000026import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
27
28/**
29 * Service using an annotated Temporal Service dependendency.
30 */
31@Service(provide = {})
32public class TemporalTest implements Runnable
33{
34 Thread m_thread;
35
36 @ServiceDependency
37 Sequencer m_sequencer;
38
39 @TemporalServiceDependency(timeout = 1000L, filter = "(test=temporal)")
40 Runnable m_service;
41
42 @Start
43 protected void start()
44 {
45 m_thread = new Thread(this);
46 m_thread.start();
47 }
48
49 @Stop
50 protected void stop()
51 {
52 m_thread.interrupt();
53 try
54 {
55 m_thread.join();
56 }
57 catch (InterruptedException e)
58 {
59 }
60 }
61
62 public void run()
63 {
64 m_service.run();
65 m_sequencer.waitForStep(2, 15000);
66 m_service.run(); // we should block here
67 m_sequencer.waitForStep(4, 15000);
68 try
69 {
70 m_service.run(); // should raise IllegalStateException
71 }
72 catch (IllegalStateException e)
73 {
74 m_sequencer.step(5);
75 }
76 }
77}