Skip to content

Commit

Permalink
change signature methods(listener instead of observer)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Nov 2, 2023
1 parent c695db1 commit 8aab2ac
Show file tree
Hide file tree
Showing 23 changed files with 99 additions and 99 deletions.
16 changes: 8 additions & 8 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
6417DD232A39CAB2008912D6 /* LatencyDiagnostic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6417DD1E2A39C9A7008912D6 /* LatencyDiagnostic.swift */; };
641A599A2AB4794E003899FB /* TradeETH.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641A59992AB4794E003899FB /* TradeETH.swift */; };
641AC1A92A61AE4000EF6D6C /* DXAliases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641AC1A82A61AE4000EF6D6C /* DXAliases.swift */; };
641BCBBC2A20ED8100FE23C2 /* DXEndpointObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BCBBB2A20ED8100FE23C2 /* DXEndpointObserver.swift */; };
641BCBBC2A20ED8100FE23C2 /* DXEndpointListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BCBBB2A20ED8100FE23C2 /* DXEndpointListener.swift */; };
641BCBC12A21077800FE23C2 /* EventCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BCBC02A21077800FE23C2 /* EventCode.swift */; };
641BDD582AC71CCE00236B78 /* LatencyTestTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 641BDD572AC71CCE00236B78 /* LatencyTestTool.swift */; };
641BDD592AC7215200236B78 /* LatencyDiagnostic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6417DD1E2A39C9A7008912D6 /* LatencyDiagnostic.swift */; };
Expand Down Expand Up @@ -321,7 +321,7 @@
64DA26B82AA20095005B1757 /* NativeInstrumentProfileConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B72AA20095005B1757 /* NativeInstrumentProfileConnection.swift */; };
64DA26BA2AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B92AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift */; };
64DA26BC2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BB2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift */; };
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift */; };
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift */; };
64DA26C02AA224EB005B1757 /* NativeIPFConnectionListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */; };
64DB79342A376E1B00229597 /* DXFeedFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; };
64DB79352A376E1B00229597 /* DXFeedFramework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 803BAC0D29BFA50700FFAB1C /* DXFeedFramework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -561,7 +561,7 @@
641AC1A82A61AE4000EF6D6C /* DXAliases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXAliases.swift; sourceTree = "<group>"; };
641BCBB32A1F8ABA00FE23C2 /* XCTestCase+Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+Utils.swift"; sourceTree = "<group>"; };
641BCBB92A1FB42500FE23C2 /* TestListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestListener.swift; sourceTree = "<group>"; };
641BCBBB2A20ED8100FE23C2 /* DXEndpointObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXEndpointObserver.swift; sourceTree = "<group>"; };
641BCBBB2A20ED8100FE23C2 /* DXEndpointListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXEndpointListener.swift; sourceTree = "<group>"; };
641BCBC02A21077800FE23C2 /* EventCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventCode.swift; sourceTree = "<group>"; };
641BDD572AC71CCE00236B78 /* LatencyTestTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LatencyTestTool.swift; sourceTree = "<group>"; };
641BDD5A2AC72BD400236B78 /* ConcurrentWeakHashTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrentWeakHashTable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -787,7 +787,7 @@
64DA26B72AA20095005B1757 /* NativeInstrumentProfileConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileConnection.swift; sourceTree = "<group>"; };
64DA26B92AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnectionState.swift; sourceTree = "<group>"; };
64DA26BB2AA20B66005B1757 /* InstrumentProfileConnectionState+ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InstrumentProfileConnectionState+ext.swift"; sourceTree = "<group>"; };
64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnectionObserver.swift; sourceTree = "<group>"; };
64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnectionListener.swift; sourceTree = "<group>"; };
64DA26BF2AA224EB005B1757 /* NativeIPFConnectionListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeIPFConnectionListener.swift; sourceTree = "<group>"; };
64E342512AAB29CF00457994 /* InstrumentProfileType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstrumentProfileType.swift; sourceTree = "<group>"; };
64E3637A2AD83459002E2B0D /* SeriesMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeriesMapper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1384,7 +1384,7 @@
6464075C2AA1C69E006FF769 /* DXInstrumentProfileUpdateListener.swift */,
64DA26B52AA1EF47005B1757 /* DXProfileIterator.swift */,
64DA26B92AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift */,
64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift */,
64DA26BD2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift */,
);
path = Live;
sourceTree = "<group>";
Expand Down Expand Up @@ -1515,7 +1515,7 @@
64656F5A2A1B9784006A0B19 /* DXFeed.swift */,
64656F662A1CCFC2006A0B19 /* DXPublisher.swift */,
64656F6C2A1CFB10006A0B19 /* DXEndpointState.swift */,
641BCBBB2A20ED8100FE23C2 /* DXEndpointObserver.swift */,
641BCBBB2A20ED8100FE23C2 /* DXEndpointListener.swift */,
64104FC82A26298D00D1FC41 /* DXFeedSubcription.swift */,
64ACBCD82A279F7900032C53 /* DXEventListener.swift */,
);
Expand Down Expand Up @@ -2201,7 +2201,7 @@
6498E6BD2AB1E0510093A065 /* ScheduleSession.swift in Sources */,
64BDDB262AD6F6B500694210 /* IcebergType.swift in Sources */,
8088D76529C0FBCE00F240CB /* ThreadManager.swift in Sources */,
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionObserver.swift in Sources */,
64DA26BE2AA20EDB005B1757 /* DXInstrumentProfileConnectionListener.swift in Sources */,
64656F732A1D0A84006A0B19 /* EndpointListener.swift in Sources */,
64BDDB282AD7D8D300694210 /* Order+Ext.swift in Sources */,
6486B9582AD00BDC00D8D5FA /* Summary.swift in Sources */,
Expand Down Expand Up @@ -2232,7 +2232,7 @@
6428EF282AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift in Sources */,
64BDDB222AD6CC9A00694210 /* SpreadOrder.swift in Sources */,
640C3FCE2A61788500555161 /* CandleExchange.swift in Sources */,
641BCBBC2A20ED8100FE23C2 /* DXEndpointObserver.swift in Sources */,
641BCBBC2A20ED8100FE23C2 /* DXEndpointListener.swift in Sources */,
6486B9792AD04F4000D8D5FA /* OrderBase.swift in Sources */,
64656F772A1DFED9006A0B19 /* EndpointState+Native.swift in Sources */,
6498E6B52AB1D4480093A065 /* NativeSchedule.swift in Sources */,
Expand Down
32 changes: 16 additions & 16 deletions DXFeedFramework/Api/DXEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public class DXEndpoint {
private lazy var publisher: DXPublisher? = {
try? DXPublisher(native: endpointNative.getNativePublisher())
}()
/// A list of state change listeners callback. observersSet - not typed variable(as storage).
private var observersSet = ConcurrentWeakHashTable<DXEndpointObserver>()
/// A list of state change listeners callback. listeneresSet - not typed variable(as storage).
private var listeneresSet = ConcurrentWeakHashTable<DXEndpointListener>()

private static var instances = [Role: DXEndpoint]()

Expand All @@ -202,18 +202,18 @@ public class DXEndpoint {
try native.addListener(self)
}
/// Adds listener that is notified about changes in ``getState()`` property.
/// Installed listener can be removed with ``remove(_:)`` method.
public func add<O>(observer: O)
where O: DXEndpointObserver,
/// Installed listener can be removed with ``remove(listener:)`` method.
public func add<O>(listener: O)
where O: DXEndpointListener,
O: Hashable {
observersSet.insert(observer)
listeneresSet.insert(listener)
}
/// Removes listener that is notified about changes in ``getState()`` property.
/// It removes the listener that was previously installed with ``add(observer:)`` method.
public func remove<O>(_ observer: O)
where O: DXEndpointObserver,
/// It removes the listener that was previously installed with ``add(listener:)`` method.
public func remove<O>(listener: O)
where O: DXEndpointListener,
O: Hashable {
observersSet.remove(observer)
listeneresSet.remove(listener)
}
/// Creates new ``Builder`` instance.
/// Use ``Builder/build()`` to build an instance of ``DXEndpoint`` when
Expand Down Expand Up @@ -248,8 +248,8 @@ public class DXEndpoint {
/// **This method does not wait until connection actually gets established**. The actual connection establishment
/// happens asynchronously after the invocation of this method. However, this method waits until notification
/// about state transition from ``DXEndpointState/notConnected`` to ``DXEndpointState/connecting``
/// gets processed by all ``DXEndpointObserver`` that were installed via
/// ``add(observer:)`` method.
/// gets processed by all ``DXEndpointListener`` that were installed via
/// ``add(listener:)`` method.
/// - Parameters:
/// - address: The data source address.
/// - Returns: ``DXEndpoint``
Expand All @@ -267,7 +267,7 @@ public class DXEndpoint {
///
/// **Note:** The method will not connect endpoint that was not initially connected with
/// ``connect(_:)`` method or was disconnected with ``disconnect()`` method.
/// The method initiates a short-path way for reconnecting, so whether observers will have a chance to see
/// The method initiates a short-path way for reconnecting, so whether listeners will have a chance to see
/// an intermediate state ``DXEndpointState/notConnected`` depends on the implementation.
/// - Throws: GraalException. Rethrows exception from Java.recore
public func reconnect() throws {
Expand Down Expand Up @@ -514,10 +514,10 @@ public class Builder {

extension DXEndpoint: EndpointListener {
func changeState(old: DXEndpointState, new: DXEndpointState) {
observersSet.reader {
listeneresSet.reader {
let enumerator = $0.objectEnumerator()
while let observer = enumerator.nextObject() as? DXEndpointObserver {
observer.endpointDidChangeState(old: old, new: new)
while let listener = enumerator.nextObject() as? DXEndpointListener {
listener.endpointDidChangeState(old: old, new: new)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DXEndpointObserver.swift
// DXEndpointListener.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 26.05.23.
Expand All @@ -8,7 +8,7 @@
import Foundation

/// Notifies a change in the state of this endpoint.
public protocol DXEndpointObserver: AnyObject {
public protocol DXEndpointListener: AnyObject {
/// Fired when state changed
///
/// - Parameters:
Expand Down
14 changes: 7 additions & 7 deletions DXFeedFramework/Api/DXFeedSubcription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DXFeedSubcription {
/// List of event types associated with this ``DXFeedSubscription``
fileprivate let events: Set<EventCode>
/// A set listeners of events
/// observers - typed list wrapper.
/// listeners - typed list wrapper.
private let listeners = ConcurrentWeakHashTable<AnyObject>()

/// - Throws: ``GraalException`` Rethrows exception from Java, ``ArgumentException/argumentNil``
Expand All @@ -36,23 +36,23 @@ public class DXFeedSubcription {
///
/// [Javadoc](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXFeedSubscription.html#addEventListener-com.dxfeed.api.DXFeedEventListener)
/// - Throws: ``GraalException`` Rethrows exception from Java, ``ArgumentException/argumentNil``
public func add<O>(observer: O) throws
public func add<O>(listener: O) throws
where O: DXEventListener,
O: Hashable {
try listeners.reader { [weak self] in
if $0.count == 0 {
try self?.native.addListener(self)
}
}
listeners.insert(observer)
listeners.insert(listener)
}
/// Removes listener for events.
///
/// [Javadoc](https://docs.dxfeed.com/dxfeed/api/com/dxfeed/api/DXFeedSubscription.html#addEventListener-com.dxfeed.api.DXFeedEventListener-)
public func remove<O>(observer: O)
public func remove<O>(listener: O)
where O: DXEventListener,
O: Hashable {
listeners.remove(observer)
listeners.remove(listener)
}

/// Adds the specified symbol to the set of subscribed symbols.
Expand Down Expand Up @@ -97,8 +97,8 @@ extension DXFeedSubcription: DXEventListener {
public func receiveEvents(_ events: [MarketEvent]) {
listeners.reader { items in
let enumerator = items.objectEnumerator()
while let observer = enumerator.nextObject() as? DXEventListener {
observer.receiveEvents(events)
while let listener = enumerator.nextObject() as? DXEventListener {
listener.receiveEvents(events)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions DXFeedFramework/Ipf/Live/DXInstrumentProfileCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
///
/// As set of instrument profiles stored in this collector can be accessed with ``view()`` method.
/// A snapshot plus a live stream of updates can be accessed with
/// ``add(observer:)`` method.
/// ``add(listener:)`` method.
///
/// Removal of instrument profile is represented by an ``InstrumentProfile`` instance with a
/// ``InstrumentProfile/type`` equal to ``InstrumentProfileType/removed``
Expand All @@ -34,20 +34,20 @@ public class DXInstrumentProfileCollector {
/// If a set of instrument profiles is not empty, then this listener will be immediately
/// ``DXInstrumentProfileUpdateListener/instrumentProfilesUpdated(_:)``.
/// - Throws: GraalException. Rethrows exception from Java.
public func add<O>(observer: O) throws
public func add<O>(listener: O) throws
where O: DXInstrumentProfileUpdateListener,
O: Hashable {
try native.addListener(observer)
listeners.insert(observer)
try native.addListener(listener)
listeners.insert(listener)
}

/// Removes listener that is notified about any updates in the set of instrument profiles.
/// - Throws: GraalException. Rethrows exception from Java.
public func remove<O>(observer: O)
public func remove<O>(listener: O)
where O: DXInstrumentProfileUpdateListener,
O: Hashable {
native.removeListener(observer)
listeners.remove(observer)
native.removeListener(listener)
listeners.remove(listener)
}

/// Returns last modification time (in milliseconds) of instrument profiles or zero if it is unknown.
Expand Down
32 changes: 16 additions & 16 deletions DXFeedFramework/Ipf/Live/DXInstrumentProfileConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DXInstrumentProfileConnection {
private let native: NativeInstrumentProfileConnection
private let collector: DXInstrumentProfileCollector

private var observersSet = ConcurrentWeakHashTable<AnyObject>()
private var listenersSet = ConcurrentWeakHashTable<AnyObject>()

/// Creates instrument profile connection with a specified address and collector.
///
Expand Down Expand Up @@ -111,32 +111,32 @@ public class DXInstrumentProfileConnection {
native.waitUntilCompleted(timeInMs)
}

/// Adds observer that is notified about changes in ``getState()`` property.
/// Installed observer can be removed with
/// ``remove(observer:)`` method.
public func add<O>(observer: O)
where O: DXInstrumentProfileConnectionObserver,
/// Adds listener that is notified about changes in ``getState()`` property.
/// Installed listener can be removed with
/// ``remove(listener:)`` method.
public func add<O>(listener: O)
where O: DXInstrumentProfileConnectionListener,
O: Hashable {
observersSet.insert(observer)
listenersSet.insert(listener)
}

/// Removes observer that is notified about changes in ``getState()`` property.
/// It removes the observer that was previously installed with
/// ``add(observer:)`` method.
public func remove<O>(observer: O)
where O: DXInstrumentProfileConnectionObserver,
/// Removes listener that is notified about changes in ``getState()`` property.
/// It removes the listener that was previously installed with
/// ``add(listener:)`` method.
public func remove<O>(listener: O)
where O: DXInstrumentProfileConnectionListener,
O: Hashable {
observersSet.remove(observer)
listenersSet.remove(listener)
}

}

extension DXInstrumentProfileConnection: NativeIPFConnectionListener {
func connectionDidChangeState(old: DXInstrumentProfileConnectionState, new: DXInstrumentProfileConnectionState) {
observersSet.reader { items in
listenersSet.reader { items in
let enumerator = items.objectEnumerator()
while let observer = enumerator.nextObject() as? DXInstrumentProfileConnectionObserver {
observer.connectionDidChangeState(old: old, new: new)
while let listener = enumerator.nextObject() as? DXInstrumentProfileConnectionListener {
listener.connectionDidChangeState(old: old, new: new)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DXInstrumentProfileConnectionObserver.swift
// DXInstrumentProfileConnectionListener.swift
// DXFeedFramework
//
// Created by Aleksey Kosylo on 01.09.23.
Expand All @@ -8,7 +8,7 @@
import Foundation

/// Notifies a change in the state of this connection.
public protocol DXInstrumentProfileConnectionObserver: AnyObject {
public protocol DXInstrumentProfileConnectionListener: AnyObject {
/// Fired when state changed
///
/// - Parameters:
Expand Down
Loading

0 comments on commit 8aab2ac

Please sign in to comment.