Skip to content

Commit

Permalink
More idiomatic and DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed May 29, 2014
1 parent 90e9af0 commit 9a6cc74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
15 changes: 9 additions & 6 deletions src/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ type WalConfig struct {
}

type InputPlugins struct {
Graphite GraphiteConfig `toml:"graphite"`
UdpInput UdpInputConfig `toml:"udp"`
Graphite GraphiteConfig `toml:"graphite"`
UdpInput UdpInputConfig `toml:"udp"`
UdpServersInput []UdpInputConfig `toml:"udp_servers"`
}

Expand Down Expand Up @@ -331,10 +331,7 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
GraphiteDatabase: tomlConfiguration.InputPlugins.Graphite.Database,
GraphiteUdpEnabled: tomlConfiguration.InputPlugins.Graphite.UdpEnabled,

UdpInputEnabled: tomlConfiguration.InputPlugins.UdpInput.Enabled,
UdpInputPort: tomlConfiguration.InputPlugins.UdpInput.Port,
UdpInputDatabase: tomlConfiguration.InputPlugins.UdpInput.Database,
UdpServers: tomlConfiguration.InputPlugins.UdpServersInput,
UdpServers: tomlConfiguration.InputPlugins.UdpServersInput,

RaftServerPort: tomlConfiguration.Raft.Port,
RaftTimeout: tomlConfiguration.Raft.Timeout,
Expand Down Expand Up @@ -369,6 +366,12 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
ConcurrentShardQueryLimit: defaultConcurrentShardQueryLimit,
}

config.UdpServers = append(config.UdpServers, UdpInputConfig{

This comment has been minimized.

Copy link
@tpitale

tpitale May 29, 2014

Contributor

Coooool, didn't know about append, yet.

This comment has been minimized.

Copy link
@tpitale

tpitale May 29, 2014

Contributor

Oh, and I see this turns the prior single udp config into one of the UdpServers. Then it can just be iterated over in server.go. Very nice.

Enabled: tomlConfiguration.InputPlugins.UdpInput.Enabled,
Database: tomlConfiguration.InputPlugins.UdpInput.Database,
Port: tomlConfiguration.InputPlugins.UdpInput.Port,
})

if config.LocalStoreWriteBufferSize == 0 {
config.LocalStoreWriteBufferSize = 1000
}
Expand Down
39 changes: 12 additions & 27 deletions src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,38 +137,23 @@ func (self *Server) ListenAndServe() error {
}
}

// singular UDP input
if self.Config.UdpInputEnabled {
if self.Config.UdpInputPort <= 0 || self.Config.UdpInputDatabase == "" {
// UDP input
for _, udpInput := range self.Config.UdpServers {
port := udpInput.Port
database := udpInput.Database

if port <= 0 || database == "" {
log.Warn("Cannot start udp server. please check your configuration")
} else {
log.Info("Starting UDP Listener on port %d to database %s", self.Config.UdpInputPort, self.Config.UdpInputDatabase)

self.UdpApi = udp.NewServer(self.Config.UdpInputPortString(self.Config.UdpInputPort), self.Config.UdpInputDatabase, self.Coordinator, self.ClusterConfig)
go self.UdpApi.ListenAndServe()
continue
}
}

// multiple UDP input
udpServersCount := len(self.Config.UdpServers)
if udpServersCount > 0 {
for i := 0; i < udpServersCount; i++ {

port := self.Config.UdpServers[i].Port
database := self.Config.UdpServers[i].Database
log.Info("Starting UDP Listener on port %d to database %s", port, database)

if port <= 0 || database == "" {
log.Warn("Cannot start udp server. please check your configuration")
} else {
log.Info("Starting UDP Listener on port %d to database %s", port, database)
addr := self.Config.UdpInputPortString(port)

listenAddress := self.Config.UdpInputPortString(port)

self.UdpServers[i] = udp.NewServer(listenAddress, database, self.Coordinator, self.ClusterConfig)
go self.UdpServers[i].ListenAndServe()
}

}
server := udp.NewServer(addr, database, self.Coordinator, self.ClusterConfig)
self.UdpServers = append(self.UdpServers, server)
go server.ListenAndServe()
}

// start processing continuous queries
Expand Down

0 comments on commit 9a6cc74

Please sign in to comment.