2012-03-05 16 views
0

나는 NotificationEvent의 인스턴스를 가지고있다. 이 인스턴스가 생성 될 때마다이 인스턴스를 큐에 추가했습니다. 큐의 이름은 NotificationQueue 여야합니다. NotificationEvent의javaBeans에서 대기열을 구현하는 방법

구조는 다음과 같다 :

public class NotificationEvent { 

    private String sender; 
    private String receiver; 
    private String message; 

    /** 
    * @return the sender 
    */ 
    public String getSender() { 
     return sender; 
    } 

    /** 
    * @param sender the sender to set 
    */ 
    public void setSender(String sender) { 
     this.sender = sender; 
    } 

    /** 
    * @return the receiver 
    */ 
    public String getReceiver() { 
     return receiver; 
    } 

    /** 
    * @param receiver the receiver to set 
    */ 
    public void setReceiver(String receiver) { 
     this.receiver = receiver; 
    } 

    /** 
    * @return the message 
    */ 
    public String getMessage() { 
     return message; 
    } 

    /** 
    * @param message the message to set 
    */ 
    public void setMessage(String message) { 
     this.message = message; 
    } 

은 무엇 NotificationQueue 필요한 구조해야 하는가?

답변

0

나는 다시 바퀴를 재발 명할 것을 제안합니다. 이미 Java 런타임 라이브러리에있는 인터페이스 Queue은 대기열에 있어야하는 작업을 정의합니다. 여기에 brief tutorial for the Queue interfaceQueue JavaDoc이 있습니다. 여기에도 example of using Queue implementations도 있습니다. 대기열에 대한 자신의 유형을 가지고 주장하는 경우,

Queue<NotificationEvent> eventQueue = new LinkedList<NotificationEvent>; 

또는 :

public class extends LinkedList<NotificationEvent> { 
    /** 
    * Constructs an empty list. 
    */ 
    public NotificationQueue() { 
    } 

    /** 
    * Constructs a list containing the elements of the specified collection, 
    * in the order they are returned by the 
    * collection's iterator. 
    * @param c the collection whose elements are to be placed into this list 
    * @throws NullPointerException if the specified collection is null 
    */ 
    public NotificationQueue(Collection<? extends NotificationEvent> c) { 
     super(c); 
    } 
} 

... 

NotificationQueue eventQueue == new NotificationQueue(); 

참고 :
LinkedList이 아니다

이 같은 알림 큐 개체를 만들 수 있습니다 Queue 인터페이스의 사용 가능한 구현 만, Java 런타임 라이브러리에서 이미 사용 가능한 다른 구현을 위해 Queue JavaDoc을 참조하십시오. 물론 Queue 인터페이스 구현을 직접 작성할 수도 있습니다.

관련 문제